53 static std::map<intel_x64::msrs::field_type, intel_x64::msrs::value_type> g_msrs;
57 static void vmcs_check_all()
103 {
return g_msrs[
addr]; }
107 { g_msrs[
addr] = val; }
119 { (void) eax; (void) ebx; (void) ecx; (void) edx; }
188 exit_handler_intel_x64_ut::test_vm_exit_reason_unknown()
190 MockRepository mocks;
201 exit_handler_intel_x64_ut::test_vm_exit_reason_cpuid()
203 MockRepository mocks;
215 exit_handler_intel_x64_ut::test_vm_exit_reason_invd()
217 MockRepository mocks;
229 exit_handler_intel_x64_ut::test_vm_exit_reason_vmcall_invalid_opcode()
231 MockRepository mocks;
235 ehlr.m_state_save->rax = 0x0000BEEF;
247 exit_handler_intel_x64_ut::test_vm_exit_reason_vmcall_invalid_magic()
249 MockRepository mocks;
254 ehlr.m_state_save->rdx = 0;
265 exit_handler_intel_x64_ut::test_vm_exit_reason_vmcall_protocol_version()
267 MockRepository mocks;
273 ehlr.m_state_save->rcx = 0;
288 exit_handler_intel_x64_ut::test_vm_exit_reason_vmcall_bareflank_version()
290 MockRepository mocks;
296 ehlr.m_state_save->rcx = 1;
311 exit_handler_intel_x64_ut::test_vm_exit_reason_vmcall_user_version()
313 MockRepository mocks;
319 ehlr.m_state_save->rcx = 10;
334 exit_handler_intel_x64_ut::test_vm_exit_reason_vmcall_unknown_version()
336 MockRepository mocks;
342 ehlr.m_state_save->rcx = 0x0000BEEF;
353 exit_handler_intel_x64_ut::test_vm_exit_reason_vmcall_registers()
355 MockRepository mocks;
361 ehlr.m_state_save->rcx = 1;
362 ehlr.m_state_save->rbx = 2;
363 ehlr.m_state_save->rsi = 3;
364 ehlr.m_state_save->r08 = 4;
365 ehlr.m_state_save->r09 = 5;
366 ehlr.m_state_save->r10 = 6;
367 ehlr.m_state_save->r11 = 7;
368 ehlr.m_state_save->r12 = 8;
369 ehlr.m_state_save->r13 = 9;
370 ehlr.m_state_save->r14 = 10;
371 ehlr.m_state_save->r15 = 11;
382 exit_handler_intel_x64_ut::test_vm_exit_reason_vmcall_unittest()
384 MockRepository mocks;
391 #ifdef INCLUDE_LIBCXX_UNITTESTS 409 exit_handler_intel_x64_ut::test_vm_exit_reason_vmcall_event()
411 MockRepository mocks;
427 exit_handler_intel_x64_ut::test_vm_exit_reason_vmcall_start()
429 MockRepository mocks;
445 exit_handler_intel_x64_ut::test_vm_exit_reason_vmcall_stop()
447 MockRepository mocks;
462 auto g_msg =
"{\"msg\":\"hello world\"}"_s;
463 auto g_map = std::make_unique<char[]>(100);
466 setup_mm(MockRepository &mocks)
478 setup_pt(MockRepository &mocks)
490 exit_handler_intel_x64_ut::test_vm_exit_reason_vmcall_data_unknown()
492 MockRepository mocks;
500 ehlr.m_state_save->rsi = 0x0000BEEF;
501 ehlr.m_state_save->r08 = 0x1234U;
502 ehlr.m_state_save->r09 =
g_msg.size();
503 ehlr.m_state_save->r11 = 0x1234U;
504 ehlr.m_state_save->r12 =
g_msg.size();
517 exit_handler_intel_x64_ut::test_vm_exit_reason_vmcall_data_string_unformatted_input_nullptr()
519 MockRepository mocks;
528 ehlr.m_state_save->r08 = 0;
529 ehlr.m_state_save->r09 =
g_msg.size();
530 ehlr.m_state_save->r11 = 0x1234U;
531 ehlr.m_state_save->r12 =
g_msg.size();
542 exit_handler_intel_x64_ut::test_vm_exit_reason_vmcall_data_string_unformatted_output_nullptr()
544 MockRepository mocks;
553 ehlr.m_state_save->r08 = 0x1234U;
554 ehlr.m_state_save->r09 =
g_msg.size();
555 ehlr.m_state_save->r11 = 0;
556 ehlr.m_state_save->r12 =
g_msg.size();
567 exit_handler_intel_x64_ut::test_vm_exit_reason_vmcall_data_string_unformatted_input_size_0()
569 MockRepository mocks;
578 ehlr.m_state_save->r08 = 0x1234U;
579 ehlr.m_state_save->r09 = 0;
580 ehlr.m_state_save->r11 = 0x1234U;
581 ehlr.m_state_save->r12 =
g_msg.size();
592 exit_handler_intel_x64_ut::test_vm_exit_reason_vmcall_data_string_unformatted_output_size_0()
594 MockRepository mocks;
603 ehlr.m_state_save->r08 = 0x1234U;
604 ehlr.m_state_save->r09 =
g_msg.size();
605 ehlr.m_state_save->r11 = 0x1234U;
606 ehlr.m_state_save->r12 = 0;
617 exit_handler_intel_x64_ut::test_vm_exit_reason_vmcall_data_string_unformatted_output_size_too_small()
619 MockRepository mocks;
628 ehlr.m_state_save->r08 = 0x1234U;
629 ehlr.m_state_save->r09 =
g_msg.size();
630 ehlr.m_state_save->r11 = 0x1234U;
631 ehlr.m_state_save->r12 = 5;
642 exit_handler_intel_x64_ut::test_vm_exit_reason_vmcall_data_string_unformatted_input_size_too_big()
644 MockRepository mocks;
653 ehlr.m_state_save->r08 = 0x1234U;
655 ehlr.m_state_save->r11 = 0x1234U;
667 exit_handler_intel_x64_ut::test_vm_exit_reason_vmcall_data_string_unformatted_output_size_too_big()
669 MockRepository mocks;
678 ehlr.m_state_save->r08 = 0x1234U;
679 ehlr.m_state_save->r09 =
g_msg.size();
680 ehlr.m_state_save->r11 = 0x1234U;
692 exit_handler_intel_x64_ut::test_vm_exit_reason_vmcall_data_string_unformatted_map_fails()
694 MockRepository mocks;
703 ehlr.m_state_save->r08 = 0xDEADBEEF;
704 ehlr.m_state_save->r09 =
g_msg.size();
705 ehlr.m_state_save->r11 = 0x1234U;
706 ehlr.m_state_save->r12 =
g_msg.size();
717 exit_handler_intel_x64_ut::test_vm_exit_reason_vmcall_data_string_unformatted_success()
719 MockRepository mocks;
728 ehlr.m_state_save->r08 = 0x1234U;
729 ehlr.m_state_save->r09 =
g_msg.size();
730 ehlr.m_state_save->r11 = 0x1234U;
731 ehlr.m_state_save->r12 =
g_msg.size();
744 exit_handler_intel_x64_ut::test_vm_exit_reason_vmcall_data_string_json_input_nullptr()
746 MockRepository mocks;
755 ehlr.m_state_save->r08 = 0;
756 ehlr.m_state_save->r09 =
g_msg.size();
757 ehlr.m_state_save->r11 = 0x1234U;
758 ehlr.m_state_save->r12 =
g_msg.size();
769 exit_handler_intel_x64_ut::test_vm_exit_reason_vmcall_data_string_json_output_nullptr()
771 MockRepository mocks;
780 ehlr.m_state_save->r08 = 0x1234U;
781 ehlr.m_state_save->r09 =
g_msg.size();
782 ehlr.m_state_save->r11 = 0;
783 ehlr.m_state_save->r12 =
g_msg.size();
794 exit_handler_intel_x64_ut::test_vm_exit_reason_vmcall_data_string_json_input_size_0()
796 MockRepository mocks;
805 ehlr.m_state_save->r08 = 0x1234U;
806 ehlr.m_state_save->r09 = 0;
807 ehlr.m_state_save->r11 = 0x1234U;
808 ehlr.m_state_save->r12 =
g_msg.size();
819 exit_handler_intel_x64_ut::test_vm_exit_reason_vmcall_data_string_json_output_size_0()
821 MockRepository mocks;
830 ehlr.m_state_save->r08 = 0x1234U;
831 ehlr.m_state_save->r09 =
g_msg.size();
832 ehlr.m_state_save->r11 = 0x1234U;
833 ehlr.m_state_save->r12 = 0;
844 exit_handler_intel_x64_ut::test_vm_exit_reason_vmcall_data_string_json_output_size_too_small()
846 MockRepository mocks;
855 ehlr.m_state_save->r08 = 0x1234U;
856 ehlr.m_state_save->r09 =
g_msg.size();
857 ehlr.m_state_save->r11 = 0x1234U;
858 ehlr.m_state_save->r12 = 5;
869 exit_handler_intel_x64_ut::test_vm_exit_reason_vmcall_data_string_json_input_size_too_big()
871 MockRepository mocks;
880 ehlr.m_state_save->r08 = 0x1234U;
882 ehlr.m_state_save->r11 = 0x1234U;
894 exit_handler_intel_x64_ut::test_vm_exit_reason_vmcall_data_string_json_output_size_too_big()
896 MockRepository mocks;
905 ehlr.m_state_save->r08 = 0x1234U;
906 ehlr.m_state_save->r09 =
g_msg.size();
907 ehlr.m_state_save->r11 = 0x1234U;
919 exit_handler_intel_x64_ut::test_vm_exit_reason_vmcall_data_string_json_map_fails()
921 MockRepository mocks;
930 ehlr.m_state_save->r08 = 0xDEADBEEF;
931 ehlr.m_state_save->r09 =
g_msg.size();
932 ehlr.m_state_save->r11 = 0x1234U;
933 ehlr.m_state_save->r12 =
g_msg.size();
944 exit_handler_intel_x64_ut::test_vm_exit_reason_vmcall_data_string_json_invalid()
946 MockRepository mocks;
955 ehlr.m_state_save->r08 = 0x1234U;
956 ehlr.m_state_save->r09 =
g_msg.size();
957 ehlr.m_state_save->r11 = 0x1234U;
958 ehlr.m_state_save->r12 =
g_msg.size();
960 auto msg =
"hello world"_s;
961 __builtin_memcpy(
g_map.get(), msg.data(), msg.size());
972 exit_handler_intel_x64_ut::test_vm_exit_reason_vmcall_data_string_json_success()
974 MockRepository mocks;
983 ehlr.m_state_save->r08 = 0x1234U;
984 ehlr.m_state_save->r09 =
g_msg.size();
985 ehlr.m_state_save->r11 = 0x1234U;
986 ehlr.m_state_save->r12 =
g_msg.size();
999 exit_handler_intel_x64_ut::test_vm_exit_reason_vmcall_data_data_unformatted_input_nullptr()
1001 MockRepository mocks;
1010 ehlr.m_state_save->r08 = 0;
1011 ehlr.m_state_save->r09 =
g_msg.size();
1012 ehlr.m_state_save->r11 = 0x1234U;
1013 ehlr.m_state_save->r12 =
g_msg.size();
1024 exit_handler_intel_x64_ut::test_vm_exit_reason_vmcall_data_data_unformatted_output_nullptr()
1026 MockRepository mocks;
1035 ehlr.m_state_save->r08 = 0x1234U;
1036 ehlr.m_state_save->r09 =
g_msg.size();
1037 ehlr.m_state_save->r11 = 0;
1038 ehlr.m_state_save->r12 =
g_msg.size();
1049 exit_handler_intel_x64_ut::test_vm_exit_reason_vmcall_data_data_unformatted_input_size_0()
1051 MockRepository mocks;
1060 ehlr.m_state_save->r08 = 0x1234U;
1061 ehlr.m_state_save->r09 = 0;
1062 ehlr.m_state_save->r11 = 0x1234U;
1063 ehlr.m_state_save->r12 =
g_msg.size();
1074 exit_handler_intel_x64_ut::test_vm_exit_reason_vmcall_data_data_unformatted_output_size_0()
1076 MockRepository mocks;
1085 ehlr.m_state_save->r08 = 0x1234U;
1086 ehlr.m_state_save->r09 =
g_msg.size();
1087 ehlr.m_state_save->r11 = 0x1234U;
1088 ehlr.m_state_save->r12 = 0;
1099 exit_handler_intel_x64_ut::test_vm_exit_reason_vmcall_data_data_unformatted_output_size_too_small()
1101 MockRepository mocks;
1110 ehlr.m_state_save->r08 = 0x1234U;
1111 ehlr.m_state_save->r09 =
g_msg.size();
1112 ehlr.m_state_save->r11 = 0x1234U;
1113 ehlr.m_state_save->r12 = 5;
1124 exit_handler_intel_x64_ut::test_vm_exit_reason_vmcall_data_data_unformatted_input_size_too_big()
1126 MockRepository mocks;
1135 ehlr.m_state_save->r08 = 0x1234U;
1137 ehlr.m_state_save->r11 = 0x1234U;
1149 exit_handler_intel_x64_ut::test_vm_exit_reason_vmcall_data_data_unformatted_output_size_too_big()
1151 MockRepository mocks;
1160 ehlr.m_state_save->r08 = 0x1234U;
1161 ehlr.m_state_save->r09 =
g_msg.size();
1162 ehlr.m_state_save->r11 = 0x1234U;
1174 exit_handler_intel_x64_ut::test_vm_exit_reason_vmcall_data_data_unformatted_map_fails()
1176 MockRepository mocks;
1185 ehlr.m_state_save->r08 = 0xDEADBEEF;
1186 ehlr.m_state_save->r09 =
g_msg.size();
1187 ehlr.m_state_save->r11 = 0x1234U;
1188 ehlr.m_state_save->r12 =
g_msg.size();
1199 exit_handler_intel_x64_ut::test_vm_exit_reason_vmcall_data_data_unformatted_success()
1201 MockRepository mocks;
1210 ehlr.m_state_save->r08 = 0x1234U;
1211 ehlr.m_state_save->r09 =
g_msg.size();
1212 ehlr.m_state_save->r11 = 0x1234U;
1213 ehlr.m_state_save->r12 =
g_msg.size();
1226 exit_handler_intel_x64_ut::test_vm_exit_reason_vmxoff()
1228 MockRepository mocks;
1239 exit_handler_intel_x64_ut::test_vm_exit_reason_rdmsr_debug_ctl()
1241 MockRepository mocks;
1260 exit_handler_intel_x64_ut::test_vm_exit_reason_rdmsr_pat()
1262 MockRepository mocks;
1282 exit_handler_intel_x64_ut::test_vm_exit_reason_rdmsr_efer()
1284 MockRepository mocks;
1304 exit_handler_intel_x64_ut::test_vm_exit_reason_rdmsr_perf()
1306 MockRepository mocks;
1326 exit_handler_intel_x64_ut::test_vm_exit_reason_rdmsr_cs()
1328 MockRepository mocks;
1347 exit_handler_intel_x64_ut::test_vm_exit_reason_rdmsr_esp()
1349 MockRepository mocks;
1368 exit_handler_intel_x64_ut::test_vm_exit_reason_rdmsr_eip()
1370 MockRepository mocks;
1389 exit_handler_intel_x64_ut::test_vm_exit_reason_rdmsr_fs_base()
1391 MockRepository mocks;
1410 exit_handler_intel_x64_ut::test_vm_exit_reason_rdmsr_gs_base()
1412 MockRepository mocks;
1431 exit_handler_intel_x64_ut::test_vm_exit_reason_rdmsr_default()
1433 MockRepository mocks;
1437 g_msrs[0x10] = 0x0000000A00000009;
1438 ehlr.m_state_save->rcx = 0x10;
1451 exit_handler_intel_x64_ut::test_vm_exit_reason_rdmsr_ignore()
1453 MockRepository mocks;
1458 ehlr.m_state_save->rcx = 0x31;
1471 exit_handler_intel_x64_ut::test_vm_exit_reason_wrmsr_debug_ctrl()
1473 MockRepository mocks;
1478 ehlr.m_state_save->rax = 0x1;
1479 ehlr.m_state_save->rdx = 0x2;
1492 exit_handler_intel_x64_ut::test_vm_exit_reason_wrmsr_pat()
1494 MockRepository mocks;
1499 ehlr.m_state_save->rax = 0x2;
1500 ehlr.m_state_save->rdx = 0x3;
1514 exit_handler_intel_x64_ut::test_vm_exit_reason_wrmsr_efer()
1516 MockRepository mocks;
1521 ehlr.m_state_save->rax = 0x3;
1522 ehlr.m_state_save->rdx = 0x4;
1536 exit_handler_intel_x64_ut::test_vm_exit_reason_wrmsr_perf()
1538 MockRepository mocks;
1543 ehlr.m_state_save->rax = 0x3;
1544 ehlr.m_state_save->rdx = 0x4;
1558 exit_handler_intel_x64_ut::test_vm_exit_reason_wrmsr_cs()
1560 MockRepository mocks;
1565 ehlr.m_state_save->rax = 0x4;
1566 ehlr.m_state_save->rdx = 0x5;
1579 exit_handler_intel_x64_ut::test_vm_exit_reason_wrmsr_esp()
1581 MockRepository mocks;
1586 ehlr.m_state_save->rax = 0x5;
1587 ehlr.m_state_save->rdx = 0x6;
1600 exit_handler_intel_x64_ut::test_vm_exit_reason_wrmsr_eip()
1602 MockRepository mocks;
1607 ehlr.m_state_save->rax = 0x6;
1608 ehlr.m_state_save->rdx = 0x7;
1621 exit_handler_intel_x64_ut::test_vm_exit_reason_wrmsr_fs_base()
1623 MockRepository mocks;
1628 ehlr.m_state_save->rax = 0x7;
1629 ehlr.m_state_save->rdx = 0x8;
1642 exit_handler_intel_x64_ut::test_vm_exit_reason_wrmsr_gs_base()
1644 MockRepository mocks;
1649 ehlr.m_state_save->rax = 0x8;
1650 ehlr.m_state_save->rdx = 0x9;
1663 exit_handler_intel_x64_ut::test_vm_exit_reason_wrmsr_default()
1665 MockRepository mocks;
1669 ehlr.m_state_save->rcx = 0x10;
1670 ehlr.m_state_save->rax = 0x9;
1671 ehlr.m_state_save->rdx = 0xA;
1676 this->
expect_true(g_msrs[0x10] = 0x0000000A00000009);
1682 exit_handler_intel_x64_ut::test_vm_exit_failure_check()
1684 MockRepository mocks;
1697 exit_handler_intel_x64_ut::test_halt()
1699 MockRepository mocks;
constexpr const auto cpuid
virtual pointer alloc_map(size_type size) noexcept
virtual void set_vmcs(gsl::not_null< vmcs_intel_x64 *> vmcs)
virtual void launch(gsl::not_null< vmcs_intel_x64_state *> host_state, gsl::not_null< vmcs_intel_x64_state *> guest_state)
auto setup_vmcs_unhandled(MockRepository &mocks, vmcs::value_type reason)
vmcs::value_type g_exit_reason
#define USER_VERSION_MAJOR
constexpr const auto addr
#define BF_VMCALL_FAILURE
#define RUN_UNITTEST_WITH_MOCKS(a, b)
constexpr const auto addr
#define VMCALL_IN_BUFFER_SIZE
constexpr const auto addr
void __wbinvd(void) noexcept
#define USER_VERSION_PATCH
#define expect_no_exception(f)
constexpr const auto addr
exit_handler_intel_x64 setup_ehlr(gsl::not_null< vmcs_intel_x64 *> vmcs)
void __stop(void) noexcept
uint64_t __read_msr(uint32_t addr) noexcept
constexpr const auto addr
bool __vmread(uint64_t field, uint64_t *val) noexcept
auto setup_vmcs_halt(MockRepository &mocks, vmcs::value_type reason)
constexpr const auto xrstors
#define VMCALL_OUT_BUFFER_SIZE
constexpr const auto addr
#define BAREFLANK_VERSION_PATCH
#define BF_VMCALL_SUCCESS
#define BAREFLANK_VERSION_MINOR
constexpr const auto invd
constexpr const auto rdmsr
void uint64_t uint64_t uint64_t *rdx noexcept
constexpr const auto addr
virtual void map_4k(integer_pointer virt, integer_pointer phys, attr_type attr)
constexpr const auto addr
virtual void unmap(integer_pointer virt) noexcept
constexpr const auto mask
auto setup_vmcs_handled(MockRepository &mocks, vmcs::value_type reason)
constexpr const auto addr
#define USER_VERSION_MINOR
void __write_msr(uint32_t addr, uint64_t val) noexcept
static memory_manager_x64 * instance() noexcept
vmcs::value_type g_exit_instruction_information
constexpr const auto mask
constexpr const auto addr
constexpr const auto addr
bool __vmwrite(uint64_t field, uint64_t val) noexcept
constexpr const auto mask
constexpr const auto addr
#define BAREFLANK_VERSION_MAJOR
constexpr const auto addr
void __cpuid(void *eax, void *ebx, void *ecx, void *edx) noexcept
constexpr const auto wrmsr
virtual void free_map(pointer ptr) noexcept
state_save_intel_x64 g_state_save
constexpr const auto addr
constexpr const auto addr
constexpr const auto vmxoff
vmcs::value_type g_exit_instruction_length
vmcs::value_type g_exit_qualification
#define VMCALL_MAGIC_NUMBER
root_page_table_x64 * root_pt() noexcept