vmcs_intel_x64_vmm_state.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 VMCS_INTEL_X64_VMM_STATE_H
23 #define VMCS_INTEL_X64_VMM_STATE_H
24 
25 #include <memory>
26 
27 #include <debug.h>
29 
30 extern tss_x64 g_tss;
31 extern gdt_x64 g_gdt;
32 extern idt_x64 g_idt;
33 
49 {
50 public:
51 
53  ~vmcs_intel_x64_vmm_state() override = default;
54 
56  { return m_cs; }
58  { return m_ss; }
60  { return m_fs; }
62  { return m_gs; }
64  { return m_tr; }
65 
67  { return m_cr0; }
69  { return m_cr3; }
71  { return m_cr4; }
72 
74  { return m_rflags; }
75 
77  { return g_gdt.base(); }
79  { return g_idt.base(); }
80 
81  gdt_x64::size_type gdt_limit() const override
82  { return g_gdt.limit(); }
83  idt_x64::size_type idt_limit() const override
84  { return g_idt.limit(); }
85 
86  gdt_x64::limit_type cs_limit() const override
87  { return g_gdt.limit(m_cs_index); }
88  gdt_x64::limit_type ss_limit() const override
89  { return g_gdt.limit(m_ss_index); }
90  gdt_x64::limit_type fs_limit() const override
91  { return g_gdt.limit(m_fs_index); }
92  gdt_x64::limit_type gs_limit() const override
93  { return g_gdt.limit(m_gs_index); }
94  gdt_x64::limit_type tr_limit() const override
95  { return g_gdt.limit(m_tr_index); }
96 
98  { return g_gdt.access_rights(m_cs_index); }
100  { return g_gdt.access_rights(m_ss_index); }
102  { return g_gdt.access_rights(m_fs_index); }
104  { return g_gdt.access_rights(m_gs_index); }
106  { return g_gdt.access_rights(m_tr_index); }
107 
108  gdt_x64::base_type cs_base() const override
109  { return g_gdt.base(m_cs_index); }
110  gdt_x64::base_type ss_base() const override
111  { return g_gdt.base(m_ss_index); }
112  gdt_x64::base_type fs_base() const override
113  { return g_gdt.base(m_fs_index); }
114  gdt_x64::base_type gs_base() const override
115  { return g_gdt.base(m_gs_index); }
116  gdt_x64::base_type tr_base() const override
117  { return g_gdt.base(m_tr_index); }
118 
120  { return m_ia32_pat_msr; }
122  { return m_ia32_efer_msr; }
123 
124  void dump() const override
125  {
126  bfdebug << "----------------------------------------" << bfendl;
127  bfdebug << "- vmcs_intel_x64_vmm_state dump -" << bfendl;
128  bfdebug << "----------------------------------------" << bfendl;
129 
130  bfdebug << bfendl;
131  bfdebug << "segment selectors:" << bfendl;
132  bfdebug << " - m_cs: " << view_as_pointer(m_cs) << bfendl;
133  bfdebug << " - m_ss: " << view_as_pointer(m_ss) << bfendl;
134  bfdebug << " - m_fs: " << view_as_pointer(m_fs) << bfendl;
135  bfdebug << " - m_gs: " << view_as_pointer(m_gs) << bfendl;
136  bfdebug << " - m_tr: " << view_as_pointer(m_tr) << bfendl;
137 
138  bfdebug << bfendl;
139  bfdebug << "segment base:" << bfendl;
140  bfdebug << " - cs_base(): " << view_as_pointer(cs_base()) << bfendl;
141  bfdebug << " - ss_base(): " << view_as_pointer(ss_base()) << bfendl;
142  bfdebug << " - fs_base(): " << view_as_pointer(fs_base()) << bfendl;
143  bfdebug << " - gs_base(): " << view_as_pointer(gs_base()) << bfendl;
144  bfdebug << " - tr_base(): " << view_as_pointer(tr_base()) << bfendl;
145 
146  bfdebug << bfendl;
147  bfdebug << "segment limit:" << bfendl;
148  bfdebug << " - cs_limit(): " << view_as_pointer(cs_limit()) << bfendl;
149  bfdebug << " - ss_limit(): " << view_as_pointer(ss_limit()) << bfendl;
150  bfdebug << " - fs_limit(): " << view_as_pointer(fs_limit()) << bfendl;
151  bfdebug << " - gs_limit(): " << view_as_pointer(gs_limit()) << bfendl;
152  bfdebug << " - tr_limit(): " << view_as_pointer(tr_limit()) << bfendl;
153 
154  bfdebug << bfendl;
155  bfdebug << "segment acess rights:" << bfendl;
156  bfdebug << " - cs_access_rights(): " << view_as_pointer(cs_access_rights()) << bfendl;
157  bfdebug << " - ss_access_rights(): " << view_as_pointer(ss_access_rights()) << bfendl;
158  bfdebug << " - fs_access_rights(): " << view_as_pointer(fs_access_rights()) << bfendl;
159  bfdebug << " - gs_access_rights(): " << view_as_pointer(gs_access_rights()) << bfendl;
160  bfdebug << " - tr_access_rights(): " << view_as_pointer(tr_access_rights()) << bfendl;
161 
162  bfdebug << bfendl;
163  bfdebug << "registers:" << bfendl;
164  bfdebug << " - m_cr0: " << view_as_pointer(m_cr0) << bfendl;
165  bfdebug << " - m_cr3: " << view_as_pointer(m_cr3) << bfendl;
166  bfdebug << " - m_cr4: " << view_as_pointer(m_cr4) << bfendl;
167 
168  bfdebug << bfendl;
169  bfdebug << "flags:" << bfendl;
170  bfdebug << " - m_rflags: " << view_as_pointer(m_rflags) << bfendl;
171 
172  bfdebug << bfendl;
173  bfdebug << "gdt/idt:" << bfendl;
174  bfdebug << " - g_gdt.base(): " << view_as_pointer(g_gdt.base()) << bfendl;
175  bfdebug << " - g_gdt.limit(): " << view_as_pointer(g_gdt.limit()) << bfendl;
176  bfdebug << " - g_idt.base(): " << view_as_pointer(g_idt.base()) << bfendl;
177  bfdebug << " - g_idt.limit(): " << view_as_pointer(g_idt.limit()) << bfendl;
178 
179  bfdebug << bfendl;
180  bfdebug << "model specific registers:" << bfendl;
181  bfdebug << " - m_ia32_pat_msr: " << view_as_pointer(m_ia32_pat_msr) << bfendl;
182  bfdebug << " - m_ia32_efer_msr: " << view_as_pointer(m_ia32_efer_msr) << bfendl;
183 
184  bfdebug << bfendl;
185  }
186 
187 private:
188 
194 
195  x64::segment_register::type m_cs_index;
196  x64::segment_register::type m_ss_index;
197  x64::segment_register::type m_fs_index;
198  x64::segment_register::type m_gs_index;
199  x64::segment_register::type m_tr_index;
200 
204 
205  x64::rflags::value_type m_rflags;
206 
207  intel_x64::msrs::value_type m_ia32_pat_msr;
208  intel_x64::msrs::value_type m_ia32_efer_msr;
209 };
210 
211 #endif
gdt_x64::base_type fs_base() const override
gdt_x64::access_rights_type cs_access_rights() const override
intel_x64::cr3::value_type cr3() const override
x64::segment_register::type tr() const override
auto base() const
Definition: idt_x64.h:212
idt_x64 g_idt
intel_x64::cr4::value_type cr4() const override
access_rights_type access_rights(index_type index) const
Definition: gdt_x64.h:534
gdt_x64::access_rights_type gs_access_rights() const override
idt_x64::size_type idt_limit() const override
gdt_x64::limit_type tr_limit() const override
gdt_x64::limit_type fs_limit() const override
gdt_x64::limit_type gs_limit() const override
x64::segment_register::type ss() const override
gdt_x64::base_type gs_base() const override
x64::segment_register::type fs() const override
intel_x64::msrs::value_type ia32_efer_msr() const override
uint64_t value_type
Definition: crs_intel_x64.h:46
gdt_x64::base_type tr_base() const override
gdt_x64::base_type cs_base() const override
uintptr_t integer_pointer
Definition: idt_x64.h:159
~vmcs_intel_x64_vmm_state() override=default
gdt_x64::base_type ss_base() const override
x64::segment_register::type cs() const override
uint32_t access_rights_type
Definition: gdt_x64.h:199
intel_x64::cr0::value_type cr0() const override
uint16_t size_type
Definition: idt_x64.h:158
x64::rflags::value_type rflags() const override
gdt_x64::limit_type cs_limit() const override
const void * view_as_pointer(const T val)
uint64_t base_type
Definition: gdt_x64.h:197
x64::segment_register::type gs() const override
uint64_t value_type
Definition: rflags_x64.h:39
tss_x64 g_tss
gdt_x64::size_type gdt_limit() const override
integer_pointer base() const
Definition: gdt_x64.h:260
intel_x64::msrs::value_type ia32_pat_msr() const override
size_type limit() const
Definition: gdt_x64.h:270
gdt_x64::integer_pointer gdt_base() const override
uint64_t value_type
gdt_x64::access_rights_type ss_access_rights() const override
idt_x64::integer_pointer idt_base() const override
gdt_x64 g_gdt
uintptr_t integer_pointer
Definition: gdt_x64.h:196
uint32_t limit_type
Definition: gdt_x64.h:198
uint64_t value_type
gdt_x64::access_rights_type fs_access_rights() const override
gdt_x64::access_rights_type tr_access_rights() const override
uint16_t size_type
Definition: gdt_x64.h:194
auto limit() const
Definition: idt_x64.h:222
uint64_t value_type
gdt_x64::limit_type ss_limit() const override