mem_attr_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 // Author: Connor Davis <davisc@ainfosec.com>
8 //
9 // This library is free software; you can redistribute it and/or
10 // modify it under the terms of the GNU Lesser General Public
11 // License as published by the Free Software Foundation; either
12 // version 2.1 of the License, or (at your option) any later version.
13 //
14 // This library is distributed in the hope that it will be useful,
15 // but WITHOUT ANY WARRANTY; without even the implied warranty of
16 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 // Lesser General Public License for more details.
18 //
19 // You should have received a copy of the GNU Lesser General Public
20 // License along with this library; if not, write to the Free Software
21 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
22 
23 #ifndef MEM_ATTR_X64_H
24 #define MEM_ATTR_X64_H
25 
26 #include <intrinsics/x64.h>
27 
28 // *INDENT-OFF*
29 
30 namespace x64
31 {
32 
33 namespace memory_attr
34 {
35  using attr_type = uint64_t;
36 
37  constexpr const auto invalid = 0x00000000UL;
38 
39  constexpr const auto rw = 0x00000100UL;
40  constexpr const auto re = 0x00000200UL;
41  constexpr const auto pt = 0x00000300UL;
42 
43  constexpr const auto rw_uc = 0x00000100UL;
44  constexpr const auto rw_wc = 0x00000101UL;
45  constexpr const auto rw_wt = 0x00000104UL;
46  constexpr const auto rw_wp = 0x00000105UL;
47  constexpr const auto rw_wb = 0x00000106UL;
48  constexpr const auto rw_uc_m = 0x00000107UL;
49 
50  constexpr const auto re_uc = 0x00000200UL;
51  constexpr const auto re_wc = 0x00000201UL;
52  constexpr const auto re_wt = 0x00000204UL;
53  constexpr const auto re_wp = 0x00000205UL;
54  constexpr const auto re_wb = 0x00000206UL;
55  constexpr const auto re_uc_m = 0x00000207UL;
56 
57  constexpr const auto pt_uc = 0x00000300UL;
58  constexpr const auto pt_wc = 0x00000301UL;
59  constexpr const auto pt_wt = 0x00000304UL;
60  constexpr const auto pt_wp = 0x00000305UL;
61  constexpr const auto pt_wb = 0x00000306UL;
62  constexpr const auto pt_uc_m = 0x00000307UL;
63 
64  template<class P, class T,
65  class = typename std::enable_if<std::is_integral<P>::value>::type,
66  class = typename std::enable_if<std::is_integral<T>::value>::type>
67  auto mem_type_to_attr(P perm, T type)
68  {
69  // Memory types are defined in x64::memory_type, and do not contain
70  // permission information which is needed by certain functions. This
71  // function converts memory types to memory attributes given desired
72  // permission information from the user.
73 
74  switch(perm)
75  {
76  case rw: break;
77  case re: break;
78 
79  default:
80  throw std::runtime_error("mem_type_to_attr failed: invalid permissions");
81  }
82 
83  switch(type)
84  {
85  case memory_type::uncacheable: break;
86  case memory_type::write_combining: break;
87  case memory_type::write_through: break;
88  case memory_type::write_protected: break;
89  case memory_type::write_back: break;
91 
92  default:
93  throw std::runtime_error("mem_type_to_attr failed: invalid memory type");
94  }
95 
96  return perm | type;
97  }
98 }
99 
100 }
101 
102 // *INDENT-ON*
103 
104 #endif
constexpr const auto pt_wp
Definition: mem_attr_x64.h:60
constexpr const auto re_wc
Definition: mem_attr_x64.h:51
constexpr const auto re_wp
Definition: mem_attr_x64.h:53
constexpr const auto re_uc_m
Definition: mem_attr_x64.h:55
constexpr const auto rw_uc_m
Definition: mem_attr_x64.h:48
constexpr const auto invalid
Definition: mem_attr_x64.h:37
constexpr const auto pt_wb
Definition: mem_attr_x64.h:61
constexpr const auto pt
Definition: mem_attr_x64.h:41
constexpr const auto rw
Definition: mem_attr_x64.h:39
constexpr const auto re_wt
Definition: mem_attr_x64.h:52
constexpr const auto rw_wb
Definition: mem_attr_x64.h:47
uint64_t attr_type
Definition: mem_attr_x64.h:35
constexpr const auto rw_uc
Definition: mem_attr_x64.h:43
constexpr const auto write_back
Definition: x64.h:46
constexpr const auto pt_wt
Definition: mem_attr_x64.h:59
constexpr const auto re_uc
Definition: mem_attr_x64.h:50
constexpr const auto pt_wc
Definition: mem_attr_x64.h:58
constexpr const auto uncacheable_minus
Definition: x64.h:47
constexpr const auto pt_uc
Definition: mem_attr_x64.h:57
constexpr const auto rw_wc
Definition: mem_attr_x64.h:44
constexpr const auto write_protected
Definition: x64.h:45
constexpr const auto pt_uc_m
Definition: mem_attr_x64.h:62
constexpr const auto uncacheable
Definition: x64.h:42
auto mem_type_to_attr(P perm, T type)
Definition: mem_attr_x64.h:67
constexpr const auto rw_wt
Definition: mem_attr_x64.h:45
Definition: cache_x64.h:31
constexpr const auto rw_wp
Definition: mem_attr_x64.h:46
constexpr const auto write_through
Definition: x64.h:44
constexpr const auto re_wb
Definition: mem_attr_x64.h:54
constexpr const auto write_combining
Definition: x64.h:43
constexpr const auto re
Definition: mem_attr_x64.h:40