page_table_entry_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_ENTRY_X64_H
23 #define PAGE_TABLE_ENTRY_X64_H
24 
25 #include <gsl/gsl>
26 
27 // -----------------------------------------------------------------------------
28 // Constants
29 // -----------------------------------------------------------------------------
30 
31 // *INDENT-OFF*
32 
33 namespace x64
34 {
35 namespace page_table
36 {
37  constexpr const auto num_entries = 512UL;
38  constexpr const auto num_bytes = num_entries * sizeof(uintptr_t);
39 
40  template<class T, class F> auto index(const T virt, const F from)
41  { return (virt & ((0x1FFULL) << from)) >> from; }
42 
43  namespace pml4
44  {
45  constexpr const auto from = 39U;
46  constexpr const auto size = 9U;
47  constexpr const auto size_bytes = 0x8000000000UL;
48  }
49 
50  namespace pdpt
51  {
52  constexpr const auto from = 30U;
53  constexpr const auto size = 9U;
54  constexpr const auto size_bytes = 0x40000000UL;
55  }
56 
57  namespace pd
58  {
59  constexpr const auto from = 21U;
60  constexpr const auto size = 9U;
61  constexpr const auto size_bytes = 0x200000UL;
62  }
63 
64  namespace pt
65  {
66  constexpr const auto from = 12U;
67  constexpr const auto size = 9U;
68  constexpr const auto size_bytes = 0x1000UL;
69  }
70 }
71 }
72 
73 // *INDENT-ON*
74 
75 // -----------------------------------------------------------------------------
76 // Definition
77 // -----------------------------------------------------------------------------
78 
80 {
81 public:
82 
83  using pointer = uintptr_t *;
84  using integer_pointer = uintptr_t;
85  using pat_index_type = uint64_t;
86 
94  page_table_entry_x64(gsl::not_null<pointer> pte) noexcept;
95 
101  ~page_table_entry_x64() = default;
102 
110  bool present() const noexcept;
111 
119  void set_present(bool enabled) noexcept;
120 
128  bool rw() const noexcept;
129 
137  void set_rw(bool enabled) noexcept;
138 
146  bool us() const noexcept;
147 
156  void set_us(bool enabled) noexcept;
157 
165  bool pwt() const noexcept;
166 
174  void set_pwt(bool enabled) noexcept;
175 
183  bool pcd() const noexcept;
184 
193  void set_pcd(bool enabled) noexcept;
194 
202  bool accessed() const noexcept;
203 
212  void set_accessed(bool enabled) noexcept;
213 
221  bool dirty() const noexcept;
222 
230  void set_dirty(bool enabled) noexcept;
231 
239  bool ps() const noexcept;
240 
249  void set_ps(bool enabled) noexcept;
250 
258  bool pat_4k() const noexcept;
259 
268  void set_pat_4k(bool enabled) noexcept;
269 
277  bool pat_large() const noexcept;
278 
287  void set_pat_large(bool enabled) noexcept;
288 
296  bool global() const noexcept;
297 
305  void set_global(bool enabled) noexcept;
306 
314  integer_pointer phys_addr() const noexcept;
315 
323  void set_phys_addr(integer_pointer addr) noexcept;
324 
332  bool nx() const noexcept;
333 
341  void set_nx(bool enabled) noexcept;
342 
350  pat_index_type pat_index_4k() const noexcept;
351 
360 
368  pat_index_type pat_index_large() const noexcept;
369 
378 
384  void clear() noexcept;
385 
386 private:
387 
388  pointer m_pte;
389 
390 public:
391 
392  page_table_entry_x64(page_table_entry_x64 &&) noexcept = default;
393  page_table_entry_x64 &operator=(page_table_entry_x64 &&) noexcept = default;
394 
395  page_table_entry_x64(const page_table_entry_x64 &) = delete;
396  page_table_entry_x64 &operator=(const page_table_entry_x64 &) = delete;
397 };
398 
399 #endif
uintptr_t integer_pointer
~page_table_entry_x64()=default
bool pwt() const noexcept
void set_pat_index_4k(pat_index_type index)
void set_nx(bool enabled) noexcept
constexpr const auto num_entries
constexpr const auto size
page_table_entry_x64(gsl::not_null< pointer > pte) noexcept
bool rw() const noexcept
void set_us(bool enabled) noexcept
void set_dirty(bool enabled) noexcept
void set_pat_large(bool enabled) noexcept
constexpr const auto from
void set_pcd(bool enabled) noexcept
bool pat_4k() const noexcept
void set_pat_4k(bool enabled) noexcept
bool present() const noexcept
void set_phys_addr(integer_pointer addr) noexcept
constexpr const auto size
constexpr const auto size_bytes
void clear() noexcept
constexpr const auto size
constexpr const auto size_bytes
void set_present(bool enabled) noexcept
constexpr const auto pt
Definition: mem_attr_x64.h:41
bool pcd() const noexcept
bool dirty() const noexcept
constexpr const auto size
void uint64_t uint64_t uint64_t *rdx noexcept
constexpr const auto size_bytes
uint64_t pat_index_type
void set_global(bool enabled) noexcept
constexpr const auto size_bytes
constexpr const auto from
auto index(const T virt, const F from)
constexpr const auto addr
Definition: cpuid_x64.h:80
void set_accessed(bool enabled) noexcept
constexpr const auto num_bytes
constexpr page_table_x64::integer_pointer virt
bool pat_large() const noexcept
bool ps() const noexcept
pat_index_type pat_index_large() const noexcept
void set_rw(bool enabled) noexcept
uintptr_t * pointer
bool accessed() const noexcept
pat_index_type pat_index_4k() const noexcept
constexpr const auto from
Definition: cache_x64.h:31
void set_pat_index_large(pat_index_type index)
void set_pwt(bool enabled) noexcept
integer_pointer phys_addr() const noexcept
constexpr const auto from
bool nx() const noexcept
void set_ps(bool enabled) noexcept
bool global() const noexcept
bool us() const noexcept