39 m_vmxon_enabled(false),
40 m_vmxon_region_phys(0)
46 if (cr4::vmx_enable_bit::get())
47 throw std::logic_error(
"vmxon already enabled");
57 auto ___ = gsl::on_failure([&]
62 auto ___ = gsl::on_failure([&]
65 if (!cr4::vmx_enable_bit::get())
66 throw std::logic_error(
"failed to enable VMXON");
78 if (cr4::vmx_enable_bit::get())
79 throw std::logic_error(
"failed to disable VMXON");
87 if (!cpuid::feature_information::ecx::vmx::get())
88 throw std::logic_error(
"VMX extensions not supported");
94 if (msrs::ia32_vmx_basic::physical_address_width::get())
95 throw std::logic_error(
"invalid physical address width");
98 throw std::logic_error(
"invalid memory type");
100 if (!msrs::ia32_vmx_basic::true_based_controls::get())
101 throw std::logic_error(
"invalid vmx true based controls");
107 auto cr0 = cr0::get();
108 auto ia32_vmx_cr0_fixed0 = msrs::ia32_vmx_cr0_fixed0::get();
109 auto ia32_vmx_cr0_fixed1 = msrs::ia32_vmx_cr0_fixed1::get();
111 if (0 != ((~cr0 & ia32_vmx_cr0_fixed0) | (cr0 & ~ia32_vmx_cr0_fixed1)))
112 throw std::logic_error(
"invalid cr0");
118 auto cr4 = cr4::get();
119 auto ia32_vmx_cr4_fixed0 = msrs::ia32_vmx_cr4_fixed0::get();
120 auto ia32_vmx_cr4_fixed1 = msrs::ia32_vmx_cr4_fixed1::get();
122 if (0 != ((~cr4 & ia32_vmx_cr4_fixed0) | (cr4 & ~ia32_vmx_cr4_fixed1)))
123 throw std::logic_error(
"invalid cr4");
129 if (msrs::ia32_feature_control::lock_bit::get())
139 if (rflags::virtual_8086_mode::get())
140 throw std::logic_error(
"v8086 mode is not supported");
146 auto ___ = gsl::on_failure([&]
149 m_vmxon_region = std::make_unique<uint32_t[]>(1024);
150 m_vmxon_region_phys =
g_mm->virtptr_to_physint(m_vmxon_region.get());
152 gsl::span<uint32_t>
id{m_vmxon_region.get(), 1024};
153 id[0] = gsl::narrow<uint32_t>(msrs::ia32_vmx_basic::revision_id::get());
159 m_vmxon_region.reset();
160 m_vmxon_region_phys = 0;
166 auto ___ = gsl::on_success([&]
167 { m_vmxon_enabled =
true; });
170 throw std::logic_error(
"vmxon has already been executed");
178 auto ___ = gsl::on_success([&]
179 { m_vmxon_enabled =
false; });
181 if (!m_vmxon_enabled)
183 bfwarning <<
"execute_vmxoff: VMX operation already disabled" << bfendl;
void check_ia32_vmx_cr0_fixed_msr()
void check_vmx_capabilities_msr()
void check_ia32_vmx_cr4_fixed_msr()
void uint64_t uint64_t uint64_t *rdx noexcept
void create_vmxon_region()
void check_ia32_feature_control_msr()
constexpr const auto write_back
void check_cpuid_vmx_supported()
void check_v8086_disabled()
void on(gsl::not_null< void *> ptr)
void release_vmxon_region() noexcept