test_exit_handler_intel_x64.cpp
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 #include <test.h>
23 
24 #include <vmcs/vmcs_intel_x64.h>
32 
35 
38 
39 #include <intrinsics/msrs_x64.h>
41 
42 using namespace x64;
43 using namespace intel_x64;
44 using namespace vmcs;
45 
52 
53 static std::map<intel_x64::msrs::field_type, intel_x64::msrs::value_type> g_msrs;
54 
55 uintptr_t g_rip = 0;
56 
57 static void vmcs_check_all()
58 { }
59 
60 extern "C" bool
61 __vmread(uint64_t field, uint64_t *val) noexcept
62 {
63  switch (field)
64  {
66  *val = g_exit_reason;
67  break;
69  *val = g_exit_qualification;
70  break;
73  break;
76  break;
78  *val = 0x0;
79  break;
81  *val = 0x0;
82  break;
83  default:
84  g_field = field;
85  *val = g_value;
86  break;
87  }
88 
89  return true;
90 }
91 
92 extern "C" bool
93 __vmwrite(uint64_t field, uint64_t val) noexcept
94 {
95  g_field = field;
96  g_value = val;
97 
98  return true;
99 }
100 
101 extern "C" uint64_t
103 { return g_msrs[addr]; }
104 
105 extern "C" void
106 __write_msr(uint32_t addr, uint64_t val) noexcept
107 { g_msrs[addr] = val; }
108 
109 extern "C" void
111 { }
112 
113 extern "C" void
115 { }
116 
117 extern "C" void
118 __cpuid(void *eax, void *ebx, void *ecx, void *edx) noexcept
119 { (void) eax; (void) ebx; (void) ecx; (void) edx; }
120 
122 
123 auto
124 setup_vmcs_unhandled(MockRepository &mocks, vmcs::value_type reason)
125 {
126  auto vmcs = mocks.Mock<vmcs_intel_x64>();
127 
128  mocks.NeverCall(vmcs, vmcs_intel_x64::launch);
129  mocks.NeverCall(vmcs, vmcs_intel_x64::promote);
130  mocks.NeverCall(vmcs, vmcs_intel_x64::load);
131  mocks.NeverCall(vmcs, vmcs_intel_x64::clear);
132  mocks.ExpectCall(vmcs, vmcs_intel_x64::resume);
133 
134  g_msrs[intel_x64::msrs::ia32_vmx_procbased_ctls2::addr] = 0xFFFFFFFF00000000UL;
135  g_msrs[intel_x64::msrs::ia32_vmx_true_pinbased_ctls::addr] = 0xFFFFFFFF00000000UL;
136  g_msrs[intel_x64::msrs::ia32_vmx_true_procbased_ctls::addr] = 0xFFFFFFFF00000000UL;
137  g_msrs[intel_x64::msrs::ia32_vmx_true_exit_ctls::addr] = 0xFFFFFFFF00000000UL;
138  g_msrs[intel_x64::msrs::ia32_vmx_true_entry_ctls::addr] = 0xFFFFFFFF00000000UL;
139 
140  g_exit_reason = reason;
141  return vmcs;
142 }
143 
144 auto
145 setup_vmcs_handled(MockRepository &mocks, vmcs::value_type reason)
146 {
147  auto vmcs = mocks.Mock<vmcs_intel_x64>();
148 
149  mocks.OnCall(vmcs, vmcs_intel_x64::launch);
150  mocks.OnCall(vmcs, vmcs_intel_x64::promote);
151  mocks.OnCall(vmcs, vmcs_intel_x64::load);
152  mocks.OnCall(vmcs, vmcs_intel_x64::clear);
153  mocks.ExpectCall(vmcs, vmcs_intel_x64::resume);
154 
155  g_msrs[intel_x64::msrs::ia32_vmx_true_entry_ctls::addr] = 0xFFFFFFFFFFFFFFFFUL;
156  g_exit_reason = reason;
157  return vmcs;
158 }
159 
160 auto
161 setup_vmcs_halt(MockRepository &mocks, vmcs::value_type reason)
162 {
163  auto vmcs = mocks.Mock<vmcs_intel_x64>();
164 
165  mocks.NeverCall(vmcs, vmcs_intel_x64::launch);
166  mocks.NeverCall(vmcs, vmcs_intel_x64::promote);
167  mocks.NeverCall(vmcs, vmcs_intel_x64::load);
168  mocks.NeverCall(vmcs, vmcs_intel_x64::clear);
169  mocks.NeverCall(vmcs, vmcs_intel_x64::resume);
170 
171  g_msrs[intel_x64::msrs::ia32_vmx_true_entry_ctls::addr] = 0xFFFFFFFFFFFFFFFFUL;
172  g_exit_reason = reason;
173  return vmcs;
174 }
175 
177 setup_ehlr(gsl::not_null<vmcs_intel_x64 *> vmcs)
178 {
179  auto ehlr = exit_handler_intel_x64{};
180  ehlr.set_vmcs(vmcs);
181  ehlr.set_state_save(&g_state_save);
182 
183  g_rip = ehlr.m_state_save->rip + g_exit_instruction_length;
184  return ehlr;
185 }
186 
187 void
188 exit_handler_intel_x64_ut::test_vm_exit_reason_unknown()
189 {
190  MockRepository mocks;
191  auto &&vmcs = setup_vmcs_unhandled(mocks, 0x0000BEEF);
192  auto &&ehlr = setup_ehlr(vmcs);
193 
194  RUN_UNITTEST_WITH_MOCKS(mocks, [&]
195  {
196  this->expect_no_exception([&]{ ehlr.dispatch(); });
197  });
198 }
199 
200 void
201 exit_handler_intel_x64_ut::test_vm_exit_reason_cpuid()
202 {
203  MockRepository mocks;
205  auto &&ehlr = setup_ehlr(vmcs);
206 
207  RUN_UNITTEST_WITH_MOCKS(mocks, [&]
208  {
209  this->expect_no_exception([&]{ ehlr.dispatch(); });
210  this->expect_true(ehlr.m_state_save->rip == g_rip);
211  });
212 }
213 
214 void
215 exit_handler_intel_x64_ut::test_vm_exit_reason_invd()
216 {
217  MockRepository mocks;
219  auto &&ehlr = setup_ehlr(vmcs);
220 
221  RUN_UNITTEST_WITH_MOCKS(mocks, [&]
222  {
223  this->expect_no_exception([&]{ ehlr.dispatch(); });
224  this->expect_true(ehlr.m_state_save->rip == g_rip);
225  });
226 }
227 
228 void
229 exit_handler_intel_x64_ut::test_vm_exit_reason_vmcall_invalid_opcode()
230 {
231  MockRepository mocks;
233  auto &&ehlr = setup_ehlr(vmcs);
234 
235  ehlr.m_state_save->rax = 0x0000BEEF;
236  ehlr.m_state_save->rdx = VMCALL_MAGIC_NUMBER;
237 
238  RUN_UNITTEST_WITH_MOCKS(mocks, [&]
239  {
240  this->expect_no_exception([&]{ ehlr.dispatch(); });
241  this->expect_true(ehlr.m_state_save->rip == g_rip);
242  this->expect_true(ec_sign(ehlr.m_state_save->rdx) == BF_VMCALL_FAILURE);
243  });
244 }
245 
246 void
247 exit_handler_intel_x64_ut::test_vm_exit_reason_vmcall_invalid_magic()
248 {
249  MockRepository mocks;
251  auto &&ehlr = setup_ehlr(vmcs);
252 
253  ehlr.m_state_save->rax = VMCALL_VERSIONS;
254  ehlr.m_state_save->rdx = 0;
255 
256  RUN_UNITTEST_WITH_MOCKS(mocks, [&]
257  {
258  this->expect_no_exception([&]{ ehlr.dispatch(); });
259  this->expect_true(ehlr.m_state_save->rip == g_rip);
260  this->expect_true(ec_sign(ehlr.m_state_save->rdx) == BF_VMCALL_FAILURE);
261  });
262 }
263 
264 void
265 exit_handler_intel_x64_ut::test_vm_exit_reason_vmcall_protocol_version()
266 {
267  MockRepository mocks;
269  auto &&ehlr = setup_ehlr(vmcs);
270 
271  ehlr.m_state_save->rax = VMCALL_VERSIONS;
272  ehlr.m_state_save->rdx = VMCALL_MAGIC_NUMBER;
273  ehlr.m_state_save->rcx = 0;
274 
275  RUN_UNITTEST_WITH_MOCKS(mocks, [&]
276  {
277  this->expect_no_exception([&]{ ehlr.dispatch(); });
278  this->expect_true(ehlr.m_state_save->rip == g_rip);
279  this->expect_true(ec_sign(ehlr.m_state_save->rdx) == BF_VMCALL_SUCCESS);
280 
281  this->expect_true(ehlr.m_state_save->rbx == VMCALL_VERSION);
282  this->expect_true(ehlr.m_state_save->rsi == 0);
283  this->expect_true(ehlr.m_state_save->r08 == 0);
284  });
285 }
286 
287 void
288 exit_handler_intel_x64_ut::test_vm_exit_reason_vmcall_bareflank_version()
289 {
290  MockRepository mocks;
292  auto &&ehlr = setup_ehlr(vmcs);
293 
294  ehlr.m_state_save->rax = VMCALL_VERSIONS;
295  ehlr.m_state_save->rdx = VMCALL_MAGIC_NUMBER;
296  ehlr.m_state_save->rcx = 1;
297 
298  RUN_UNITTEST_WITH_MOCKS(mocks, [&]
299  {
300  this->expect_no_exception([&]{ ehlr.dispatch(); });
301  this->expect_true(ehlr.m_state_save->rip == g_rip);
302  this->expect_true(ec_sign(ehlr.m_state_save->rdx) == BF_VMCALL_SUCCESS);
303 
304  this->expect_true(ehlr.m_state_save->rbx == BAREFLANK_VERSION_MAJOR);
305  this->expect_true(ehlr.m_state_save->rsi == BAREFLANK_VERSION_MINOR);
306  this->expect_true(ehlr.m_state_save->r08 == BAREFLANK_VERSION_PATCH);
307  });
308 }
309 
310 void
311 exit_handler_intel_x64_ut::test_vm_exit_reason_vmcall_user_version()
312 {
313  MockRepository mocks;
315  auto &&ehlr = setup_ehlr(vmcs);
316 
317  ehlr.m_state_save->rax = VMCALL_VERSIONS;
318  ehlr.m_state_save->rdx = VMCALL_MAGIC_NUMBER;
319  ehlr.m_state_save->rcx = 10;
320 
321  RUN_UNITTEST_WITH_MOCKS(mocks, [&]
322  {
323  this->expect_no_exception([&]{ ehlr.dispatch(); });
324  this->expect_true(ehlr.m_state_save->rip == g_rip);
325  this->expect_true(ec_sign(ehlr.m_state_save->rdx) == BF_VMCALL_SUCCESS);
326 
327  this->expect_true(ehlr.m_state_save->rbx == USER_VERSION_MAJOR);
328  this->expect_true(ehlr.m_state_save->rsi == USER_VERSION_MINOR);
329  this->expect_true(ehlr.m_state_save->r08 == USER_VERSION_PATCH);
330  });
331 }
332 
333 void
334 exit_handler_intel_x64_ut::test_vm_exit_reason_vmcall_unknown_version()
335 {
336  MockRepository mocks;
338  auto &&ehlr = setup_ehlr(vmcs);
339 
340  ehlr.m_state_save->rax = VMCALL_VERSIONS;
341  ehlr.m_state_save->rdx = VMCALL_MAGIC_NUMBER;
342  ehlr.m_state_save->rcx = 0x0000BEEF;
343 
344  RUN_UNITTEST_WITH_MOCKS(mocks, [&]
345  {
346  this->expect_no_exception([&]{ ehlr.dispatch(); });
347  this->expect_true(ehlr.m_state_save->rip == g_rip);
348  this->expect_true(ec_sign(ehlr.m_state_save->rdx) == BF_VMCALL_FAILURE);
349  });
350 }
351 
352 void
353 exit_handler_intel_x64_ut::test_vm_exit_reason_vmcall_registers()
354 {
355  MockRepository mocks;
357  auto &&ehlr = setup_ehlr(vmcs);
358 
359  ehlr.m_state_save->rax = VMCALL_REGISTERS;
360  ehlr.m_state_save->rdx = VMCALL_MAGIC_NUMBER;
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;
372 
373  RUN_UNITTEST_WITH_MOCKS(mocks, [&]
374  {
375  this->expect_no_exception([&]{ ehlr.dispatch(); });
376  this->expect_true(ehlr.m_state_save->rip == g_rip);
377  this->expect_true(ec_sign(ehlr.m_state_save->rdx) == BF_VMCALL_SUCCESS);
378  });
379 }
380 
381 void
382 exit_handler_intel_x64_ut::test_vm_exit_reason_vmcall_unittest()
383 {
384  MockRepository mocks;
386  auto &&ehlr = setup_ehlr(vmcs);
387 
388  ehlr.m_state_save->rax = VMCALL_UNITTEST;
389  ehlr.m_state_save->rdx = VMCALL_MAGIC_NUMBER;
390 
391 #ifdef INCLUDE_LIBCXX_UNITTESTS
392  RUN_UNITTEST_WITH_MOCKS(mocks, [&]
393  {
394  this->expect_no_exception([&]{ ehlr.dispatch(); });
395  this->expect_true(ehlr.m_state_save->rip == g_rip);
396  this->expect_true(ec_sign(ehlr.m_state_save->rdx) == BF_VMCALL_FAILURE);
397  });
398 #else
399  RUN_UNITTEST_WITH_MOCKS(mocks, [&]
400  {
401  this->expect_no_exception([&]{ ehlr.dispatch(); });
402  this->expect_true(ehlr.m_state_save->rip == g_rip);
403  this->expect_true(ec_sign(ehlr.m_state_save->rdx) == BF_VMCALL_SUCCESS);
404  });
405 #endif
406 }
407 
408 void
409 exit_handler_intel_x64_ut::test_vm_exit_reason_vmcall_event()
410 {
411  MockRepository mocks;
413  auto &&ehlr = setup_ehlr(vmcs);
414 
415  ehlr.m_state_save->rax = VMCALL_EVENT;
416  ehlr.m_state_save->rdx = VMCALL_MAGIC_NUMBER;
417 
418  RUN_UNITTEST_WITH_MOCKS(mocks, [&]
419  {
420  this->expect_no_exception([&]{ ehlr.dispatch(); });
421  this->expect_true(ehlr.m_state_save->rip == g_rip);
422  this->expect_true(ec_sign(ehlr.m_state_save->rdx) == BF_VMCALL_SUCCESS);
423  });
424 }
425 
426 void
427 exit_handler_intel_x64_ut::test_vm_exit_reason_vmcall_start()
428 {
429  MockRepository mocks;
431  auto &&ehlr = setup_ehlr(vmcs);
432 
433  ehlr.m_state_save->rax = VMCALL_START;
434  ehlr.m_state_save->rdx = VMCALL_MAGIC_NUMBER;
435 
436  RUN_UNITTEST_WITH_MOCKS(mocks, [&]
437  {
438  this->expect_no_exception([&]{ ehlr.dispatch(); });
439  this->expect_true(ehlr.m_state_save->rip == g_rip);
440  this->expect_true(ec_sign(ehlr.m_state_save->rdx) == BF_VMCALL_SUCCESS);
441  });
442 }
443 
444 void
445 exit_handler_intel_x64_ut::test_vm_exit_reason_vmcall_stop()
446 {
447  MockRepository mocks;
449  auto &&ehlr = setup_ehlr(vmcs);
450 
451  ehlr.m_state_save->rax = VMCALL_STOP;
452  ehlr.m_state_save->rdx = VMCALL_MAGIC_NUMBER;
453 
454  RUN_UNITTEST_WITH_MOCKS(mocks, [&]
455  {
456  this->expect_no_exception([&]{ ehlr.dispatch(); });
457  this->expect_true(ehlr.m_state_save->rip == g_rip);
458  this->expect_true(ec_sign(ehlr.m_state_save->rdx) == BF_VMCALL_SUCCESS);
459  });
460 }
461 
462 auto g_msg = "{\"msg\":\"hello world\"}"_s;
463 auto g_map = std::make_unique<char[]>(100);
464 
465 static auto
466 setup_mm(MockRepository &mocks)
467 {
468  auto mm = mocks.Mock<memory_manager_x64>();
469  mocks.OnCallFunc(memory_manager_x64::instance).Return(mm);
470 
471  mocks.OnCall(mm, memory_manager_x64::alloc_map).Return(g_map.get());
472  mocks.OnCall(mm, memory_manager_x64::free_map);
473 
474  return mm;
475 }
476 
477 static auto
478 setup_pt(MockRepository &mocks)
479 {
480  auto pt = mocks.Mock<root_page_table_x64>();
481  mocks.OnCallFunc(root_pt).Return(pt);
482 
483  mocks.OnCall(pt, root_page_table_x64::map_4k);
484  mocks.OnCall(pt, root_page_table_x64::unmap);
485 
486  return pt;
487 }
488 
489 void
490 exit_handler_intel_x64_ut::test_vm_exit_reason_vmcall_data_unknown()
491 {
492  MockRepository mocks;
494  auto &&ehlr = setup_ehlr(vmcs);
495  setup_mm(mocks);
496  setup_pt(mocks);
497 
498  ehlr.m_state_save->rax = VMCALL_DATA; // r00
499  ehlr.m_state_save->rdx = VMCALL_MAGIC_NUMBER; // r01
500  ehlr.m_state_save->rsi = 0x0000BEEF; // r04
501  ehlr.m_state_save->r08 = 0x1234U; // r05
502  ehlr.m_state_save->r09 = g_msg.size(); // r06
503  ehlr.m_state_save->r11 = 0x1234U; // r08
504  ehlr.m_state_save->r12 = g_msg.size(); // r09
505 
506  __builtin_memcpy(g_map.get(), g_msg.data(), g_msg.size());
507 
508  RUN_UNITTEST_WITH_MOCKS(mocks, [&]
509  {
510  this->expect_no_exception([&]{ ehlr.dispatch(); });
511  this->expect_true(ehlr.m_state_save->rip == g_rip);
512  this->expect_true(ec_sign(ehlr.m_state_save->rdx) == BF_VMCALL_FAILURE);
513  });
514 }
515 
516 void
517 exit_handler_intel_x64_ut::test_vm_exit_reason_vmcall_data_string_unformatted_input_nullptr()
518 {
519  MockRepository mocks;
521  auto &&ehlr = setup_ehlr(vmcs);
522  setup_mm(mocks);
523  setup_pt(mocks);
524 
525  ehlr.m_state_save->rax = VMCALL_DATA; // r00
526  ehlr.m_state_save->rdx = VMCALL_MAGIC_NUMBER; // r01
527  ehlr.m_state_save->rsi = VMCALL_DATA_STRING_UNFORMATTED; // r04
528  ehlr.m_state_save->r08 = 0; // r05
529  ehlr.m_state_save->r09 = g_msg.size(); // r06
530  ehlr.m_state_save->r11 = 0x1234U; // r08
531  ehlr.m_state_save->r12 = g_msg.size(); // r09
532 
533  RUN_UNITTEST_WITH_MOCKS(mocks, [&]
534  {
535  this->expect_no_exception([&]{ ehlr.dispatch(); });
536  this->expect_true(ehlr.m_state_save->rip == g_rip);
537  this->expect_true(ec_sign(ehlr.m_state_save->rdx) == BF_VMCALL_FAILURE);
538  });
539 }
540 
541 void
542 exit_handler_intel_x64_ut::test_vm_exit_reason_vmcall_data_string_unformatted_output_nullptr()
543 {
544  MockRepository mocks;
546  auto &&ehlr = setup_ehlr(vmcs);
547  setup_mm(mocks);
548  setup_pt(mocks);
549 
550  ehlr.m_state_save->rax = VMCALL_DATA; // r00
551  ehlr.m_state_save->rdx = VMCALL_MAGIC_NUMBER; // r01
552  ehlr.m_state_save->rsi = VMCALL_DATA_STRING_UNFORMATTED; // r04
553  ehlr.m_state_save->r08 = 0x1234U; // r05
554  ehlr.m_state_save->r09 = g_msg.size(); // r06
555  ehlr.m_state_save->r11 = 0; // r08
556  ehlr.m_state_save->r12 = g_msg.size(); // r09
557 
558  RUN_UNITTEST_WITH_MOCKS(mocks, [&]
559  {
560  this->expect_no_exception([&]{ ehlr.dispatch(); });
561  this->expect_true(ehlr.m_state_save->rip == g_rip);
562  this->expect_true(ec_sign(ehlr.m_state_save->rdx) == BF_VMCALL_FAILURE);
563  });
564 }
565 
566 void
567 exit_handler_intel_x64_ut::test_vm_exit_reason_vmcall_data_string_unformatted_input_size_0()
568 {
569  MockRepository mocks;
571  auto &&ehlr = setup_ehlr(vmcs);
572  setup_mm(mocks);
573  setup_pt(mocks);
574 
575  ehlr.m_state_save->rax = VMCALL_DATA; // r00
576  ehlr.m_state_save->rdx = VMCALL_MAGIC_NUMBER; // r01
577  ehlr.m_state_save->rsi = VMCALL_DATA_STRING_UNFORMATTED; // r04
578  ehlr.m_state_save->r08 = 0x1234U; // r05
579  ehlr.m_state_save->r09 = 0; // r06
580  ehlr.m_state_save->r11 = 0x1234U; // r08
581  ehlr.m_state_save->r12 = g_msg.size(); // r09
582 
583  RUN_UNITTEST_WITH_MOCKS(mocks, [&]
584  {
585  this->expect_no_exception([&]{ ehlr.dispatch(); });
586  this->expect_true(ehlr.m_state_save->rip == g_rip);
587  this->expect_true(ec_sign(ehlr.m_state_save->rdx) == BF_VMCALL_FAILURE);
588  });
589 }
590 
591 void
592 exit_handler_intel_x64_ut::test_vm_exit_reason_vmcall_data_string_unformatted_output_size_0()
593 {
594  MockRepository mocks;
596  auto &&ehlr = setup_ehlr(vmcs);
597  setup_mm(mocks);
598  setup_pt(mocks);
599 
600  ehlr.m_state_save->rax = VMCALL_DATA; // r00
601  ehlr.m_state_save->rdx = VMCALL_MAGIC_NUMBER; // r01
602  ehlr.m_state_save->rsi = VMCALL_DATA_STRING_UNFORMATTED; // r04
603  ehlr.m_state_save->r08 = 0x1234U; // r05
604  ehlr.m_state_save->r09 = g_msg.size(); // r06
605  ehlr.m_state_save->r11 = 0x1234U; // r08
606  ehlr.m_state_save->r12 = 0; // r09
607 
608  RUN_UNITTEST_WITH_MOCKS(mocks, [&]
609  {
610  this->expect_no_exception([&]{ ehlr.dispatch(); });
611  this->expect_true(ehlr.m_state_save->rip == g_rip);
612  this->expect_true(ec_sign(ehlr.m_state_save->rdx) == BF_VMCALL_FAILURE);
613  });
614 }
615 
616 void
617 exit_handler_intel_x64_ut::test_vm_exit_reason_vmcall_data_string_unformatted_output_size_too_small()
618 {
619  MockRepository mocks;
621  auto &&ehlr = setup_ehlr(vmcs);
622  setup_mm(mocks);
623  setup_pt(mocks);
624 
625  ehlr.m_state_save->rax = VMCALL_DATA; // r00
626  ehlr.m_state_save->rdx = VMCALL_MAGIC_NUMBER; // r01
627  ehlr.m_state_save->rsi = VMCALL_DATA_STRING_UNFORMATTED; // r04
628  ehlr.m_state_save->r08 = 0x1234U; // r05
629  ehlr.m_state_save->r09 = g_msg.size(); // r06
630  ehlr.m_state_save->r11 = 0x1234U; // r08
631  ehlr.m_state_save->r12 = 5; // r09
632 
633  RUN_UNITTEST_WITH_MOCKS(mocks, [&]
634  {
635  this->expect_no_exception([&]{ ehlr.dispatch(); });
636  this->expect_true(ehlr.m_state_save->rip == g_rip);
637  this->expect_true(ec_sign(ehlr.m_state_save->rdx) == BF_VMCALL_FAILURE);
638  });
639 }
640 
641 void
642 exit_handler_intel_x64_ut::test_vm_exit_reason_vmcall_data_string_unformatted_input_size_too_big()
643 {
644  MockRepository mocks;
646  auto &&ehlr = setup_ehlr(vmcs);
647  setup_mm(mocks);
648  setup_pt(mocks);
649 
650  ehlr.m_state_save->rax = VMCALL_DATA; // r00
651  ehlr.m_state_save->rdx = VMCALL_MAGIC_NUMBER; // r01
652  ehlr.m_state_save->rsi = VMCALL_DATA_STRING_UNFORMATTED; // r04
653  ehlr.m_state_save->r08 = 0x1234U; // r05
654  ehlr.m_state_save->r09 = VMCALL_IN_BUFFER_SIZE + 1; // r06
655  ehlr.m_state_save->r11 = 0x1234U; // r08
656  ehlr.m_state_save->r12 = VMCALL_IN_BUFFER_SIZE + 1; // r09
657 
658  RUN_UNITTEST_WITH_MOCKS(mocks, [&]
659  {
660  this->expect_no_exception([&]{ ehlr.dispatch(); });
661  this->expect_true(ehlr.m_state_save->rip == g_rip);
662  this->expect_true(ec_sign(ehlr.m_state_save->rdx) == BF_VMCALL_FAILURE);
663  });
664 }
665 
666 void
667 exit_handler_intel_x64_ut::test_vm_exit_reason_vmcall_data_string_unformatted_output_size_too_big()
668 {
669  MockRepository mocks;
671  auto &&ehlr = setup_ehlr(vmcs);
672  setup_mm(mocks);
673  setup_pt(mocks);
674 
675  ehlr.m_state_save->rax = VMCALL_DATA; // r00
676  ehlr.m_state_save->rdx = VMCALL_MAGIC_NUMBER; // r01
677  ehlr.m_state_save->rsi = VMCALL_DATA_STRING_UNFORMATTED; // r04
678  ehlr.m_state_save->r08 = 0x1234U; // r05
679  ehlr.m_state_save->r09 = g_msg.size(); // r06
680  ehlr.m_state_save->r11 = 0x1234U; // r08
681  ehlr.m_state_save->r12 = VMCALL_OUT_BUFFER_SIZE + 1; // r09
682 
683  RUN_UNITTEST_WITH_MOCKS(mocks, [&]
684  {
685  this->expect_no_exception([&]{ ehlr.dispatch(); });
686  this->expect_true(ehlr.m_state_save->rip == g_rip);
687  this->expect_true(ec_sign(ehlr.m_state_save->rdx) == BF_VMCALL_FAILURE);
688  });
689 }
690 
691 void
692 exit_handler_intel_x64_ut::test_vm_exit_reason_vmcall_data_string_unformatted_map_fails()
693 {
694  MockRepository mocks;
696  auto &&ehlr = setup_ehlr(vmcs);
697  setup_mm(mocks);
698  setup_pt(mocks);
699 
700  ehlr.m_state_save->rax = VMCALL_DATA; // r00
701  ehlr.m_state_save->rdx = VMCALL_MAGIC_NUMBER; // r01
702  ehlr.m_state_save->rsi = VMCALL_DATA_STRING_UNFORMATTED; // r04
703  ehlr.m_state_save->r08 = 0xDEADBEEF; // r05
704  ehlr.m_state_save->r09 = g_msg.size(); // r06
705  ehlr.m_state_save->r11 = 0x1234U; // r08
706  ehlr.m_state_save->r12 = g_msg.size(); // r09
707 
708  RUN_UNITTEST_WITH_MOCKS(mocks, [&]
709  {
710  this->expect_no_exception([&]{ ehlr.dispatch(); });
711  this->expect_true(ehlr.m_state_save->rip == g_rip);
712  this->expect_true(ec_sign(ehlr.m_state_save->rdx) == BF_VMCALL_FAILURE);
713  });
714 }
715 
716 void
717 exit_handler_intel_x64_ut::test_vm_exit_reason_vmcall_data_string_unformatted_success()
718 {
719  MockRepository mocks;
721  auto &&ehlr = setup_ehlr(vmcs);
722  setup_mm(mocks);
723  setup_pt(mocks);
724 
725  ehlr.m_state_save->rax = VMCALL_DATA; // r00
726  ehlr.m_state_save->rdx = VMCALL_MAGIC_NUMBER; // r01
727  ehlr.m_state_save->rsi = VMCALL_DATA_STRING_UNFORMATTED; // r04
728  ehlr.m_state_save->r08 = 0x1234U; // r05
729  ehlr.m_state_save->r09 = g_msg.size(); // r06
730  ehlr.m_state_save->r11 = 0x1234U; // r08
731  ehlr.m_state_save->r12 = g_msg.size(); // r09
732 
733  __builtin_memcpy(g_map.get(), g_msg.data(), g_msg.size());
734 
735  RUN_UNITTEST_WITH_MOCKS(mocks, [&]
736  {
737  this->expect_no_exception([&]{ ehlr.dispatch(); });
738  this->expect_true(ehlr.m_state_save->rip == g_rip);
739  this->expect_true(ec_sign(ehlr.m_state_save->rdx) == BF_VMCALL_SUCCESS);
740  });
741 }
742 
743 void
744 exit_handler_intel_x64_ut::test_vm_exit_reason_vmcall_data_string_json_input_nullptr()
745 {
746  MockRepository mocks;
748  auto &&ehlr = setup_ehlr(vmcs);
749  setup_mm(mocks);
750  setup_pt(mocks);
751 
752  ehlr.m_state_save->rax = VMCALL_DATA; // r00
753  ehlr.m_state_save->rdx = VMCALL_MAGIC_NUMBER; // r01
754  ehlr.m_state_save->rsi = VMCALL_DATA_STRING_JSON; // r04
755  ehlr.m_state_save->r08 = 0; // r05
756  ehlr.m_state_save->r09 = g_msg.size(); // r06
757  ehlr.m_state_save->r11 = 0x1234U; // r08
758  ehlr.m_state_save->r12 = g_msg.size(); // r09
759 
760  RUN_UNITTEST_WITH_MOCKS(mocks, [&]
761  {
762  this->expect_no_exception([&]{ ehlr.dispatch(); });
763  this->expect_true(ehlr.m_state_save->rip == g_rip);
764  this->expect_true(ec_sign(ehlr.m_state_save->rdx) == BF_VMCALL_FAILURE);
765  });
766 }
767 
768 void
769 exit_handler_intel_x64_ut::test_vm_exit_reason_vmcall_data_string_json_output_nullptr()
770 {
771  MockRepository mocks;
773  auto &&ehlr = setup_ehlr(vmcs);
774  setup_mm(mocks);
775  setup_pt(mocks);
776 
777  ehlr.m_state_save->rax = VMCALL_DATA; // r00
778  ehlr.m_state_save->rdx = VMCALL_MAGIC_NUMBER; // r01
779  ehlr.m_state_save->rsi = VMCALL_DATA_STRING_JSON; // r04
780  ehlr.m_state_save->r08 = 0x1234U; // r05
781  ehlr.m_state_save->r09 = g_msg.size(); // r06
782  ehlr.m_state_save->r11 = 0; // r08
783  ehlr.m_state_save->r12 = g_msg.size(); // r09
784 
785  RUN_UNITTEST_WITH_MOCKS(mocks, [&]
786  {
787  this->expect_no_exception([&]{ ehlr.dispatch(); });
788  this->expect_true(ehlr.m_state_save->rip == g_rip);
789  this->expect_true(ec_sign(ehlr.m_state_save->rdx) == BF_VMCALL_FAILURE);
790  });
791 }
792 
793 void
794 exit_handler_intel_x64_ut::test_vm_exit_reason_vmcall_data_string_json_input_size_0()
795 {
796  MockRepository mocks;
798  auto &&ehlr = setup_ehlr(vmcs);
799  setup_mm(mocks);
800  setup_pt(mocks);
801 
802  ehlr.m_state_save->rax = VMCALL_DATA; // r00
803  ehlr.m_state_save->rdx = VMCALL_MAGIC_NUMBER; // r01
804  ehlr.m_state_save->rsi = VMCALL_DATA_STRING_JSON; // r04
805  ehlr.m_state_save->r08 = 0x1234U; // r05
806  ehlr.m_state_save->r09 = 0; // r06
807  ehlr.m_state_save->r11 = 0x1234U; // r08
808  ehlr.m_state_save->r12 = g_msg.size(); // r09
809 
810  RUN_UNITTEST_WITH_MOCKS(mocks, [&]
811  {
812  this->expect_no_exception([&]{ ehlr.dispatch(); });
813  this->expect_true(ehlr.m_state_save->rip == g_rip);
814  this->expect_true(ec_sign(ehlr.m_state_save->rdx) == BF_VMCALL_FAILURE);
815  });
816 }
817 
818 void
819 exit_handler_intel_x64_ut::test_vm_exit_reason_vmcall_data_string_json_output_size_0()
820 {
821  MockRepository mocks;
823  auto &&ehlr = setup_ehlr(vmcs);
824  setup_mm(mocks);
825  setup_pt(mocks);
826 
827  ehlr.m_state_save->rax = VMCALL_DATA; // r00
828  ehlr.m_state_save->rdx = VMCALL_MAGIC_NUMBER; // r01
829  ehlr.m_state_save->rsi = VMCALL_DATA_STRING_JSON; // r04
830  ehlr.m_state_save->r08 = 0x1234U; // r05
831  ehlr.m_state_save->r09 = g_msg.size(); // r06
832  ehlr.m_state_save->r11 = 0x1234U; // r08
833  ehlr.m_state_save->r12 = 0; // r09
834 
835  RUN_UNITTEST_WITH_MOCKS(mocks, [&]
836  {
837  this->expect_no_exception([&]{ ehlr.dispatch(); });
838  this->expect_true(ehlr.m_state_save->rip == g_rip);
839  this->expect_true(ec_sign(ehlr.m_state_save->rdx) == BF_VMCALL_FAILURE);
840  });
841 }
842 
843 void
844 exit_handler_intel_x64_ut::test_vm_exit_reason_vmcall_data_string_json_output_size_too_small()
845 {
846  MockRepository mocks;
848  auto &&ehlr = setup_ehlr(vmcs);
849  setup_mm(mocks);
850  setup_pt(mocks);
851 
852  ehlr.m_state_save->rax = VMCALL_DATA; // r00
853  ehlr.m_state_save->rdx = VMCALL_MAGIC_NUMBER; // r01
854  ehlr.m_state_save->rsi = VMCALL_DATA_STRING_JSON; // r04
855  ehlr.m_state_save->r08 = 0x1234U; // r05
856  ehlr.m_state_save->r09 = g_msg.size(); // r06
857  ehlr.m_state_save->r11 = 0x1234U; // r08
858  ehlr.m_state_save->r12 = 5; // r09
859 
860  RUN_UNITTEST_WITH_MOCKS(mocks, [&]
861  {
862  this->expect_no_exception([&]{ ehlr.dispatch(); });
863  this->expect_true(ehlr.m_state_save->rip == g_rip);
864  this->expect_true(ec_sign(ehlr.m_state_save->rdx) == BF_VMCALL_FAILURE);
865  });
866 }
867 
868 void
869 exit_handler_intel_x64_ut::test_vm_exit_reason_vmcall_data_string_json_input_size_too_big()
870 {
871  MockRepository mocks;
873  auto &&ehlr = setup_ehlr(vmcs);
874  setup_mm(mocks);
875  setup_pt(mocks);
876 
877  ehlr.m_state_save->rax = VMCALL_DATA; // r00
878  ehlr.m_state_save->rdx = VMCALL_MAGIC_NUMBER; // r01
879  ehlr.m_state_save->rsi = VMCALL_DATA_STRING_JSON; // r04
880  ehlr.m_state_save->r08 = 0x1234U; // r05
881  ehlr.m_state_save->r09 = VMCALL_IN_BUFFER_SIZE + 1; // r06
882  ehlr.m_state_save->r11 = 0x1234U; // r08
883  ehlr.m_state_save->r12 = VMCALL_IN_BUFFER_SIZE + 1; // r09
884 
885  RUN_UNITTEST_WITH_MOCKS(mocks, [&]
886  {
887  this->expect_no_exception([&]{ ehlr.dispatch(); });
888  this->expect_true(ehlr.m_state_save->rip == g_rip);
889  this->expect_true(ec_sign(ehlr.m_state_save->rdx) == BF_VMCALL_FAILURE);
890  });
891 }
892 
893 void
894 exit_handler_intel_x64_ut::test_vm_exit_reason_vmcall_data_string_json_output_size_too_big()
895 {
896  MockRepository mocks;
898  auto &&ehlr = setup_ehlr(vmcs);
899  setup_mm(mocks);
900  setup_pt(mocks);
901 
902  ehlr.m_state_save->rax = VMCALL_DATA; // r00
903  ehlr.m_state_save->rdx = VMCALL_MAGIC_NUMBER; // r01
904  ehlr.m_state_save->rsi = VMCALL_DATA_STRING_JSON; // r04
905  ehlr.m_state_save->r08 = 0x1234U; // r05
906  ehlr.m_state_save->r09 = g_msg.size(); // r06
907  ehlr.m_state_save->r11 = 0x1234U; // r08
908  ehlr.m_state_save->r12 = VMCALL_OUT_BUFFER_SIZE + 1; // r09
909 
910  RUN_UNITTEST_WITH_MOCKS(mocks, [&]
911  {
912  this->expect_no_exception([&]{ ehlr.dispatch(); });
913  this->expect_true(ehlr.m_state_save->rip == g_rip);
914  this->expect_true(ec_sign(ehlr.m_state_save->rdx) == BF_VMCALL_FAILURE);
915  });
916 }
917 
918 void
919 exit_handler_intel_x64_ut::test_vm_exit_reason_vmcall_data_string_json_map_fails()
920 {
921  MockRepository mocks;
923  auto &&ehlr = setup_ehlr(vmcs);
924  setup_mm(mocks);
925  setup_pt(mocks);
926 
927  ehlr.m_state_save->rax = VMCALL_DATA; // r00
928  ehlr.m_state_save->rdx = VMCALL_MAGIC_NUMBER; // r01
929  ehlr.m_state_save->rsi = VMCALL_DATA_STRING_JSON; // r04
930  ehlr.m_state_save->r08 = 0xDEADBEEF; // r05
931  ehlr.m_state_save->r09 = g_msg.size(); // r06
932  ehlr.m_state_save->r11 = 0x1234U; // r08
933  ehlr.m_state_save->r12 = g_msg.size(); // r09
934 
935  RUN_UNITTEST_WITH_MOCKS(mocks, [&]
936  {
937  this->expect_no_exception([&]{ ehlr.dispatch(); });
938  this->expect_true(ehlr.m_state_save->rip == g_rip);
939  this->expect_true(ec_sign(ehlr.m_state_save->rdx) == BF_VMCALL_FAILURE);
940  });
941 }
942 
943 void
944 exit_handler_intel_x64_ut::test_vm_exit_reason_vmcall_data_string_json_invalid()
945 {
946  MockRepository mocks;
948  auto &&ehlr = setup_ehlr(vmcs);
949  setup_mm(mocks);
950  setup_pt(mocks);
951 
952  ehlr.m_state_save->rax = VMCALL_DATA; // r00
953  ehlr.m_state_save->rdx = VMCALL_MAGIC_NUMBER; // r01
954  ehlr.m_state_save->rsi = VMCALL_DATA_STRING_JSON; // r04
955  ehlr.m_state_save->r08 = 0x1234U; // r05
956  ehlr.m_state_save->r09 = g_msg.size(); // r06
957  ehlr.m_state_save->r11 = 0x1234U; // r08
958  ehlr.m_state_save->r12 = g_msg.size(); // r09
959 
960  auto msg = "hello world"_s;
961  __builtin_memcpy(g_map.get(), msg.data(), msg.size());
962 
963  RUN_UNITTEST_WITH_MOCKS(mocks, [&]
964  {
965  this->expect_no_exception([&]{ ehlr.dispatch(); });
966  this->expect_true(ehlr.m_state_save->rip == g_rip);
967  this->expect_true(ec_sign(ehlr.m_state_save->rdx) == BF_VMCALL_FAILURE);
968  });
969 }
970 
971 void
972 exit_handler_intel_x64_ut::test_vm_exit_reason_vmcall_data_string_json_success()
973 {
974  MockRepository mocks;
976  auto &&ehlr = setup_ehlr(vmcs);
977  setup_mm(mocks);
978  setup_pt(mocks);
979 
980  ehlr.m_state_save->rax = VMCALL_DATA; // r00
981  ehlr.m_state_save->rdx = VMCALL_MAGIC_NUMBER; // r01
982  ehlr.m_state_save->rsi = VMCALL_DATA_STRING_JSON; // r04
983  ehlr.m_state_save->r08 = 0x1234U; // r05
984  ehlr.m_state_save->r09 = g_msg.size(); // r06
985  ehlr.m_state_save->r11 = 0x1234U; // r08
986  ehlr.m_state_save->r12 = g_msg.size(); // r09
987 
988  __builtin_memcpy(g_map.get(), g_msg.data(), g_msg.size());
989 
990  RUN_UNITTEST_WITH_MOCKS(mocks, [&]
991  {
992  this->expect_no_exception([&]{ ehlr.dispatch(); });
993  this->expect_true(ehlr.m_state_save->rip == g_rip);
994  this->expect_true(ec_sign(ehlr.m_state_save->rdx) == BF_VMCALL_SUCCESS);
995  });
996 }
997 
998 void
999 exit_handler_intel_x64_ut::test_vm_exit_reason_vmcall_data_data_unformatted_input_nullptr()
1000 {
1001  MockRepository mocks;
1003  auto &&ehlr = setup_ehlr(vmcs);
1004  setup_mm(mocks);
1005  setup_pt(mocks);
1006 
1007  ehlr.m_state_save->rax = VMCALL_DATA; // r00
1008  ehlr.m_state_save->rdx = VMCALL_MAGIC_NUMBER; // r01
1009  ehlr.m_state_save->rsi = VMCALL_DATA_BINARY_UNFORMATTED; // r04
1010  ehlr.m_state_save->r08 = 0; // r05
1011  ehlr.m_state_save->r09 = g_msg.size(); // r06
1012  ehlr.m_state_save->r11 = 0x1234U; // r08
1013  ehlr.m_state_save->r12 = g_msg.size(); // r09
1014 
1015  RUN_UNITTEST_WITH_MOCKS(mocks, [&]
1016  {
1017  this->expect_no_exception([&]{ ehlr.dispatch(); });
1018  this->expect_true(ehlr.m_state_save->rip == g_rip);
1019  this->expect_true(ec_sign(ehlr.m_state_save->rdx) == BF_VMCALL_FAILURE);
1020  });
1021 }
1022 
1023 void
1024 exit_handler_intel_x64_ut::test_vm_exit_reason_vmcall_data_data_unformatted_output_nullptr()
1025 {
1026  MockRepository mocks;
1028  auto &&ehlr = setup_ehlr(vmcs);
1029  setup_mm(mocks);
1030  setup_pt(mocks);
1031 
1032  ehlr.m_state_save->rax = VMCALL_DATA; // r00
1033  ehlr.m_state_save->rdx = VMCALL_MAGIC_NUMBER; // r01
1034  ehlr.m_state_save->rsi = VMCALL_DATA_BINARY_UNFORMATTED; // r04
1035  ehlr.m_state_save->r08 = 0x1234U; // r05
1036  ehlr.m_state_save->r09 = g_msg.size(); // r06
1037  ehlr.m_state_save->r11 = 0; // r08
1038  ehlr.m_state_save->r12 = g_msg.size(); // r09
1039 
1040  RUN_UNITTEST_WITH_MOCKS(mocks, [&]
1041  {
1042  this->expect_no_exception([&]{ ehlr.dispatch(); });
1043  this->expect_true(ehlr.m_state_save->rip == g_rip);
1044  this->expect_true(ec_sign(ehlr.m_state_save->rdx) == BF_VMCALL_FAILURE);
1045  });
1046 }
1047 
1048 void
1049 exit_handler_intel_x64_ut::test_vm_exit_reason_vmcall_data_data_unformatted_input_size_0()
1050 {
1051  MockRepository mocks;
1053  auto &&ehlr = setup_ehlr(vmcs);
1054  setup_mm(mocks);
1055  setup_pt(mocks);
1056 
1057  ehlr.m_state_save->rax = VMCALL_DATA; // r00
1058  ehlr.m_state_save->rdx = VMCALL_MAGIC_NUMBER; // r01
1059  ehlr.m_state_save->rsi = VMCALL_DATA_BINARY_UNFORMATTED; // r04
1060  ehlr.m_state_save->r08 = 0x1234U; // r05
1061  ehlr.m_state_save->r09 = 0; // r06
1062  ehlr.m_state_save->r11 = 0x1234U; // r08
1063  ehlr.m_state_save->r12 = g_msg.size(); // r09
1064 
1065  RUN_UNITTEST_WITH_MOCKS(mocks, [&]
1066  {
1067  this->expect_no_exception([&]{ ehlr.dispatch(); });
1068  this->expect_true(ehlr.m_state_save->rip == g_rip);
1069  this->expect_true(ec_sign(ehlr.m_state_save->rdx) == BF_VMCALL_FAILURE);
1070  });
1071 }
1072 
1073 void
1074 exit_handler_intel_x64_ut::test_vm_exit_reason_vmcall_data_data_unformatted_output_size_0()
1075 {
1076  MockRepository mocks;
1078  auto &&ehlr = setup_ehlr(vmcs);
1079  setup_mm(mocks);
1080  setup_pt(mocks);
1081 
1082  ehlr.m_state_save->rax = VMCALL_DATA; // r00
1083  ehlr.m_state_save->rdx = VMCALL_MAGIC_NUMBER; // r01
1084  ehlr.m_state_save->rsi = VMCALL_DATA_BINARY_UNFORMATTED; // r04
1085  ehlr.m_state_save->r08 = 0x1234U; // r05
1086  ehlr.m_state_save->r09 = g_msg.size(); // r06
1087  ehlr.m_state_save->r11 = 0x1234U; // r08
1088  ehlr.m_state_save->r12 = 0; // r09
1089 
1090  RUN_UNITTEST_WITH_MOCKS(mocks, [&]
1091  {
1092  this->expect_no_exception([&]{ ehlr.dispatch(); });
1093  this->expect_true(ehlr.m_state_save->rip == g_rip);
1094  this->expect_true(ec_sign(ehlr.m_state_save->rdx) == BF_VMCALL_FAILURE);
1095  });
1096 }
1097 
1098 void
1099 exit_handler_intel_x64_ut::test_vm_exit_reason_vmcall_data_data_unformatted_output_size_too_small()
1100 {
1101  MockRepository mocks;
1103  auto &&ehlr = setup_ehlr(vmcs);
1104  setup_mm(mocks);
1105  setup_pt(mocks);
1106 
1107  ehlr.m_state_save->rax = VMCALL_DATA; // r00
1108  ehlr.m_state_save->rdx = VMCALL_MAGIC_NUMBER; // r01
1109  ehlr.m_state_save->rsi = VMCALL_DATA_BINARY_UNFORMATTED; // r04
1110  ehlr.m_state_save->r08 = 0x1234U; // r05
1111  ehlr.m_state_save->r09 = g_msg.size(); // r06
1112  ehlr.m_state_save->r11 = 0x1234U; // r08
1113  ehlr.m_state_save->r12 = 5; // r09
1114 
1115  RUN_UNITTEST_WITH_MOCKS(mocks, [&]
1116  {
1117  this->expect_no_exception([&]{ ehlr.dispatch(); });
1118  this->expect_true(ehlr.m_state_save->rip == g_rip);
1119  this->expect_true(ec_sign(ehlr.m_state_save->rdx) == BF_VMCALL_FAILURE);
1120  });
1121 }
1122 
1123 void
1124 exit_handler_intel_x64_ut::test_vm_exit_reason_vmcall_data_data_unformatted_input_size_too_big()
1125 {
1126  MockRepository mocks;
1128  auto &&ehlr = setup_ehlr(vmcs);
1129  setup_mm(mocks);
1130  setup_pt(mocks);
1131 
1132  ehlr.m_state_save->rax = VMCALL_DATA; // r00
1133  ehlr.m_state_save->rdx = VMCALL_MAGIC_NUMBER; // r01
1134  ehlr.m_state_save->rsi = VMCALL_DATA_BINARY_UNFORMATTED; // r04
1135  ehlr.m_state_save->r08 = 0x1234U; // r05
1136  ehlr.m_state_save->r09 = VMCALL_IN_BUFFER_SIZE + 1; // r06
1137  ehlr.m_state_save->r11 = 0x1234U; // r08
1138  ehlr.m_state_save->r12 = VMCALL_IN_BUFFER_SIZE + 1; // r09
1139 
1140  RUN_UNITTEST_WITH_MOCKS(mocks, [&]
1141  {
1142  this->expect_no_exception([&]{ ehlr.dispatch(); });
1143  this->expect_true(ehlr.m_state_save->rip == g_rip);
1144  this->expect_true(ec_sign(ehlr.m_state_save->rdx) == BF_VMCALL_FAILURE);
1145  });
1146 }
1147 
1148 void
1149 exit_handler_intel_x64_ut::test_vm_exit_reason_vmcall_data_data_unformatted_output_size_too_big()
1150 {
1151  MockRepository mocks;
1153  auto &&ehlr = setup_ehlr(vmcs);
1154  setup_mm(mocks);
1155  setup_pt(mocks);
1156 
1157  ehlr.m_state_save->rax = VMCALL_DATA; // r00
1158  ehlr.m_state_save->rdx = VMCALL_MAGIC_NUMBER; // r01
1159  ehlr.m_state_save->rsi = VMCALL_DATA_BINARY_UNFORMATTED; // r04
1160  ehlr.m_state_save->r08 = 0x1234U; // r05
1161  ehlr.m_state_save->r09 = g_msg.size(); // r06
1162  ehlr.m_state_save->r11 = 0x1234U; // r08
1163  ehlr.m_state_save->r12 = VMCALL_OUT_BUFFER_SIZE + 1; // r09
1164 
1165  RUN_UNITTEST_WITH_MOCKS(mocks, [&]
1166  {
1167  this->expect_no_exception([&]{ ehlr.dispatch(); });
1168  this->expect_true(ehlr.m_state_save->rip == g_rip);
1169  this->expect_true(ec_sign(ehlr.m_state_save->rdx) == BF_VMCALL_FAILURE);
1170  });
1171 }
1172 
1173 void
1174 exit_handler_intel_x64_ut::test_vm_exit_reason_vmcall_data_data_unformatted_map_fails()
1175 {
1176  MockRepository mocks;
1178  auto &&ehlr = setup_ehlr(vmcs);
1179  setup_mm(mocks);
1180  setup_pt(mocks);
1181 
1182  ehlr.m_state_save->rax = VMCALL_DATA; // r00
1183  ehlr.m_state_save->rdx = VMCALL_MAGIC_NUMBER; // r01
1184  ehlr.m_state_save->rsi = VMCALL_DATA_BINARY_UNFORMATTED; // r04
1185  ehlr.m_state_save->r08 = 0xDEADBEEF; // r05
1186  ehlr.m_state_save->r09 = g_msg.size(); // r06
1187  ehlr.m_state_save->r11 = 0x1234U; // r08
1188  ehlr.m_state_save->r12 = g_msg.size(); // r09
1189 
1190  RUN_UNITTEST_WITH_MOCKS(mocks, [&]
1191  {
1192  this->expect_no_exception([&]{ ehlr.dispatch(); });
1193  this->expect_true(ehlr.m_state_save->rip == g_rip);
1194  this->expect_true(ec_sign(ehlr.m_state_save->rdx) == BF_VMCALL_FAILURE);
1195  });
1196 }
1197 
1198 void
1199 exit_handler_intel_x64_ut::test_vm_exit_reason_vmcall_data_data_unformatted_success()
1200 {
1201  MockRepository mocks;
1203  auto &&ehlr = setup_ehlr(vmcs);
1204  setup_mm(mocks);
1205  setup_pt(mocks);
1206 
1207  ehlr.m_state_save->rax = VMCALL_DATA; // r00
1208  ehlr.m_state_save->rdx = VMCALL_MAGIC_NUMBER; // r01
1209  ehlr.m_state_save->rsi = VMCALL_DATA_BINARY_UNFORMATTED; // r04
1210  ehlr.m_state_save->r08 = 0x1234U; // r05
1211  ehlr.m_state_save->r09 = g_msg.size(); // r06
1212  ehlr.m_state_save->r11 = 0x1234U; // r08
1213  ehlr.m_state_save->r12 = g_msg.size(); // r09
1214 
1215  __builtin_memcpy(g_map.get(), g_msg.data(), g_msg.size());
1216 
1217  RUN_UNITTEST_WITH_MOCKS(mocks, [&]
1218  {
1219  this->expect_no_exception([&]{ ehlr.dispatch(); });
1220  this->expect_true(ehlr.m_state_save->rip == g_rip);
1221  this->expect_true(ec_sign(ehlr.m_state_save->rdx) == BF_VMCALL_SUCCESS);
1222  });
1223 }
1224 
1225 void
1226 exit_handler_intel_x64_ut::test_vm_exit_reason_vmxoff()
1227 {
1228  MockRepository mocks;
1230  auto &&ehlr = setup_ehlr(vmcs);
1231 
1232  RUN_UNITTEST_WITH_MOCKS(mocks, [&]
1233  {
1234  this->expect_no_exception([&]{ ehlr.dispatch(); });
1235  });
1236 }
1237 
1238 void
1239 exit_handler_intel_x64_ut::test_vm_exit_reason_rdmsr_debug_ctl()
1240 {
1241  MockRepository mocks;
1243  auto &&ehlr = setup_ehlr(vmcs);
1244 
1245  g_value = 0x0000000200000001;
1246  ehlr.m_state_save->rcx = intel_x64::msrs::ia32_debugctl::addr;
1247 
1248  RUN_UNITTEST_WITH_MOCKS(mocks, [&]
1249  {
1250  this->expect_no_exception([&]{ ehlr.dispatch(); });
1251 
1253  this->expect_true(ehlr.m_state_save->rax == 0x1);
1254  this->expect_true(ehlr.m_state_save->rdx == 0x2);
1255  this->expect_true(ehlr.m_state_save->rip == g_rip);
1256  });
1257 }
1258 
1259 void
1260 exit_handler_intel_x64_ut::test_vm_exit_reason_rdmsr_pat()
1261 {
1262  MockRepository mocks;
1264  auto &&ehlr = setup_ehlr(vmcs);
1265 
1266  g_value = 0x0000000300000002;
1267  ehlr.m_state_save->rcx = x64::msrs::ia32_pat::addr;
1269 
1270  RUN_UNITTEST_WITH_MOCKS(mocks, [&]
1271  {
1272  this->expect_no_exception([&]{ ehlr.dispatch(); });
1273 
1275  this->expect_true(ehlr.m_state_save->rax == 0x2);
1276  this->expect_true(ehlr.m_state_save->rdx == 0x3);
1277  this->expect_true(ehlr.m_state_save->rip == g_rip);
1278  });
1279 }
1280 
1281 void
1282 exit_handler_intel_x64_ut::test_vm_exit_reason_rdmsr_efer()
1283 {
1284  MockRepository mocks;
1286  auto &&ehlr = setup_ehlr(vmcs);
1287 
1288  g_value = 0x0000000400000003;
1289  ehlr.m_state_save->rcx = intel_x64::msrs::ia32_efer::addr;
1291 
1292  RUN_UNITTEST_WITH_MOCKS(mocks, [&]
1293  {
1294  this->expect_no_exception([&]{ ehlr.dispatch(); });
1295 
1297  this->expect_true(ehlr.m_state_save->rax == 0x3);
1298  this->expect_true(ehlr.m_state_save->rdx == 0x4);
1299  this->expect_true(ehlr.m_state_save->rip == g_rip);
1300  });
1301 }
1302 
1303 void
1304 exit_handler_intel_x64_ut::test_vm_exit_reason_rdmsr_perf()
1305 {
1306  MockRepository mocks;
1308  auto &&ehlr = setup_ehlr(vmcs);
1309 
1310  g_value = 0x0000000400000003;
1311  ehlr.m_state_save->rcx = intel_x64::msrs::ia32_perf_global_ctrl::addr;
1313 
1314  RUN_UNITTEST_WITH_MOCKS(mocks, [&]
1315  {
1316  this->expect_no_exception([&]{ ehlr.dispatch(); });
1317 
1319  this->expect_true(ehlr.m_state_save->rax == 0x3);
1320  this->expect_true(ehlr.m_state_save->rdx == 0x4);
1321  this->expect_true(ehlr.m_state_save->rip == g_rip);
1322  });
1323 }
1324 
1325 void
1326 exit_handler_intel_x64_ut::test_vm_exit_reason_rdmsr_cs()
1327 {
1328  MockRepository mocks;
1330  auto &&ehlr = setup_ehlr(vmcs);
1331 
1332  g_value = 0x0000000500000004;
1333  ehlr.m_state_save->rcx = intel_x64::msrs::ia32_sysenter_cs::addr;
1334 
1335  RUN_UNITTEST_WITH_MOCKS(mocks, [&]
1336  {
1337  this->expect_no_exception([&]{ ehlr.dispatch(); });
1338 
1340  this->expect_true(ehlr.m_state_save->rax == 0x4);
1341  this->expect_true(ehlr.m_state_save->rdx == 0x5);
1342  this->expect_true(ehlr.m_state_save->rip == g_rip);
1343  });
1344 }
1345 
1346 void
1347 exit_handler_intel_x64_ut::test_vm_exit_reason_rdmsr_esp()
1348 {
1349  MockRepository mocks;
1351  auto &&ehlr = setup_ehlr(vmcs);
1352 
1353  g_value = 0x0000000600000005;
1354  ehlr.m_state_save->rcx = intel_x64::msrs::ia32_sysenter_esp::addr;
1355 
1356  RUN_UNITTEST_WITH_MOCKS(mocks, [&]
1357  {
1358  this->expect_no_exception([&]{ ehlr.dispatch(); });
1359 
1361  this->expect_true(ehlr.m_state_save->rax == 0x5);
1362  this->expect_true(ehlr.m_state_save->rdx == 0x6);
1363  this->expect_true(ehlr.m_state_save->rip == g_rip);
1364  });
1365 }
1366 
1367 void
1368 exit_handler_intel_x64_ut::test_vm_exit_reason_rdmsr_eip()
1369 {
1370  MockRepository mocks;
1372  auto &&ehlr = setup_ehlr(vmcs);
1373 
1374  g_value = 0x0000000700000006;
1375  ehlr.m_state_save->rcx = intel_x64::msrs::ia32_sysenter_eip::addr;
1376 
1377  RUN_UNITTEST_WITH_MOCKS(mocks, [&]
1378  {
1379  this->expect_no_exception([&]{ ehlr.dispatch(); });
1380 
1382  this->expect_true(ehlr.m_state_save->rax == 0x6);
1383  this->expect_true(ehlr.m_state_save->rdx == 0x7);
1384  this->expect_true(ehlr.m_state_save->rip == g_rip);
1385  });
1386 }
1387 
1388 void
1389 exit_handler_intel_x64_ut::test_vm_exit_reason_rdmsr_fs_base()
1390 {
1391  MockRepository mocks;
1393  auto &&ehlr = setup_ehlr(vmcs);
1394 
1395  g_value = 0x0000000800000007;
1396  ehlr.m_state_save->rcx = intel_x64::msrs::ia32_fs_base::addr;
1397 
1398  RUN_UNITTEST_WITH_MOCKS(mocks, [&]
1399  {
1400  this->expect_no_exception([&]{ ehlr.dispatch(); });
1401 
1403  this->expect_true(ehlr.m_state_save->rax == 0x7);
1404  this->expect_true(ehlr.m_state_save->rdx == 0x8);
1405  this->expect_true(ehlr.m_state_save->rip == g_rip);
1406  });
1407 }
1408 
1409 void
1410 exit_handler_intel_x64_ut::test_vm_exit_reason_rdmsr_gs_base()
1411 {
1412  MockRepository mocks;
1414  auto &&ehlr = setup_ehlr(vmcs);
1415 
1416  g_value = 0x0000000900000008;
1417  ehlr.m_state_save->rcx = intel_x64::msrs::ia32_gs_base::addr;
1418 
1419  RUN_UNITTEST_WITH_MOCKS(mocks, [&]
1420  {
1421  this->expect_no_exception([&]{ ehlr.dispatch(); });
1422 
1424  this->expect_true(ehlr.m_state_save->rax == 0x8);
1425  this->expect_true(ehlr.m_state_save->rdx == 0x9);
1426  this->expect_true(ehlr.m_state_save->rip == g_rip);
1427  });
1428 }
1429 
1430 void
1431 exit_handler_intel_x64_ut::test_vm_exit_reason_rdmsr_default()
1432 {
1433  MockRepository mocks;
1435  auto &&ehlr = setup_ehlr(vmcs);
1436 
1437  g_msrs[0x10] = 0x0000000A00000009;
1438  ehlr.m_state_save->rcx = 0x10;
1439 
1440  RUN_UNITTEST_WITH_MOCKS(mocks, [&]
1441  {
1442  this->expect_no_exception([&]{ ehlr.dispatch(); });
1443 
1444  this->expect_true(ehlr.m_state_save->rax == 0x9);
1445  this->expect_true(ehlr.m_state_save->rdx == 0xA);
1446  this->expect_true(ehlr.m_state_save->rip == g_rip);
1447  });
1448 }
1449 
1450 void
1451 exit_handler_intel_x64_ut::test_vm_exit_reason_rdmsr_ignore()
1452 {
1453  MockRepository mocks;
1455  auto &&ehlr = setup_ehlr(vmcs);
1456 
1457  g_msrs[0x31] = 0x0;
1458  ehlr.m_state_save->rcx = 0x31;
1459 
1460  RUN_UNITTEST_WITH_MOCKS(mocks, [&]
1461  {
1462  this->expect_no_exception([&]{ ehlr.dispatch(); });
1463 
1464  this->expect_true(ehlr.m_state_save->rax == 0);
1465  this->expect_true(ehlr.m_state_save->rdx == 0);
1466  this->expect_true(ehlr.m_state_save->rip == g_rip);
1467  });
1468 }
1469 
1470 void
1471 exit_handler_intel_x64_ut::test_vm_exit_reason_wrmsr_debug_ctrl()
1472 {
1473  MockRepository mocks;
1475  auto &&ehlr = setup_ehlr(vmcs);
1476 
1477  ehlr.m_state_save->rcx = intel_x64::msrs::ia32_debugctl::addr;
1478  ehlr.m_state_save->rax = 0x1;
1479  ehlr.m_state_save->rdx = 0x2;
1480 
1481  RUN_UNITTEST_WITH_MOCKS(mocks, [&]
1482  {
1483  this->expect_no_exception([&]{ ehlr.dispatch(); });
1484 
1486  this->expect_true(g_value == 0x0000000200000001);
1487  this->expect_true(ehlr.m_state_save->rip == g_rip);
1488  });
1489 }
1490 
1491 void
1492 exit_handler_intel_x64_ut::test_vm_exit_reason_wrmsr_pat()
1493 {
1494  MockRepository mocks;
1496  auto &&ehlr = setup_ehlr(vmcs);
1497 
1498  ehlr.m_state_save->rcx = x64::msrs::ia32_pat::addr;
1499  ehlr.m_state_save->rax = 0x2;
1500  ehlr.m_state_save->rdx = 0x3;
1502 
1503  RUN_UNITTEST_WITH_MOCKS(mocks, [&]
1504  {
1505  this->expect_no_exception([&]{ ehlr.dispatch(); });
1506 
1508  this->expect_true(g_value == 0x0000000300000002);
1509  this->expect_true(ehlr.m_state_save->rip == g_rip);
1510  });
1511 }
1512 
1513 void
1514 exit_handler_intel_x64_ut::test_vm_exit_reason_wrmsr_efer()
1515 {
1516  MockRepository mocks;
1518  auto &&ehlr = setup_ehlr(vmcs);
1519 
1520  ehlr.m_state_save->rcx = intel_x64::msrs::ia32_efer::addr;
1521  ehlr.m_state_save->rax = 0x3;
1522  ehlr.m_state_save->rdx = 0x4;
1524 
1525  RUN_UNITTEST_WITH_MOCKS(mocks, [&]
1526  {
1527  this->expect_no_exception([&]{ ehlr.dispatch(); });
1528 
1530  this->expect_true(g_value == 0x0000000400000003);
1531  this->expect_true(ehlr.m_state_save->rip == g_rip);
1532  });
1533 }
1534 
1535 void
1536 exit_handler_intel_x64_ut::test_vm_exit_reason_wrmsr_perf()
1537 {
1538  MockRepository mocks;
1540  auto &&ehlr = setup_ehlr(vmcs);
1541 
1542  ehlr.m_state_save->rcx = intel_x64::msrs::ia32_perf_global_ctrl::addr;
1543  ehlr.m_state_save->rax = 0x3;
1544  ehlr.m_state_save->rdx = 0x4;
1546 
1547  RUN_UNITTEST_WITH_MOCKS(mocks, [&]
1548  {
1549  this->expect_no_exception([&]{ ehlr.dispatch(); });
1550 
1552  this->expect_true(g_value == 0x0000000400000003);
1553  this->expect_true(ehlr.m_state_save->rip == g_rip);
1554  });
1555 }
1556 
1557 void
1558 exit_handler_intel_x64_ut::test_vm_exit_reason_wrmsr_cs()
1559 {
1560  MockRepository mocks;
1562  auto &&ehlr = setup_ehlr(vmcs);
1563 
1564  ehlr.m_state_save->rcx = intel_x64::msrs::ia32_sysenter_cs::addr;
1565  ehlr.m_state_save->rax = 0x4;
1566  ehlr.m_state_save->rdx = 0x5;
1567 
1568  RUN_UNITTEST_WITH_MOCKS(mocks, [&]
1569  {
1570  this->expect_no_exception([&]{ ehlr.dispatch(); });
1571 
1573  this->expect_true(g_value == 0x0000000500000004);
1574  this->expect_true(ehlr.m_state_save->rip == g_rip);
1575  });
1576 }
1577 
1578 void
1579 exit_handler_intel_x64_ut::test_vm_exit_reason_wrmsr_esp()
1580 {
1581  MockRepository mocks;
1583  auto &&ehlr = setup_ehlr(vmcs);
1584 
1585  ehlr.m_state_save->rcx = intel_x64::msrs::ia32_sysenter_esp::addr;
1586  ehlr.m_state_save->rax = 0x5;
1587  ehlr.m_state_save->rdx = 0x6;
1588 
1589  RUN_UNITTEST_WITH_MOCKS(mocks, [&]
1590  {
1591  this->expect_no_exception([&]{ ehlr.dispatch(); });
1592 
1594  this->expect_true(g_value == 0x0000000600000005);
1595  this->expect_true(ehlr.m_state_save->rip == g_rip);
1596  });
1597 }
1598 
1599 void
1600 exit_handler_intel_x64_ut::test_vm_exit_reason_wrmsr_eip()
1601 {
1602  MockRepository mocks;
1604  auto &&ehlr = setup_ehlr(vmcs);
1605 
1606  ehlr.m_state_save->rcx = intel_x64::msrs::ia32_sysenter_eip::addr;
1607  ehlr.m_state_save->rax = 0x6;
1608  ehlr.m_state_save->rdx = 0x7;
1609 
1610  RUN_UNITTEST_WITH_MOCKS(mocks, [&]
1611  {
1612  this->expect_no_exception([&]{ ehlr.dispatch(); });
1613 
1615  this->expect_true(g_value == 0x0000000700000006);
1616  this->expect_true(ehlr.m_state_save->rip == g_rip);
1617  });
1618 }
1619 
1620 void
1621 exit_handler_intel_x64_ut::test_vm_exit_reason_wrmsr_fs_base()
1622 {
1623  MockRepository mocks;
1625  auto &&ehlr = setup_ehlr(vmcs);
1626 
1627  ehlr.m_state_save->rcx = intel_x64::msrs::ia32_fs_base::addr;
1628  ehlr.m_state_save->rax = 0x7;
1629  ehlr.m_state_save->rdx = 0x8;
1630 
1631  RUN_UNITTEST_WITH_MOCKS(mocks, [&]
1632  {
1633  this->expect_no_exception([&]{ ehlr.dispatch(); });
1634 
1636  this->expect_true(g_value == 0x0000000800000007);
1637  this->expect_true(ehlr.m_state_save->rip == g_rip);
1638  });
1639 }
1640 
1641 void
1642 exit_handler_intel_x64_ut::test_vm_exit_reason_wrmsr_gs_base()
1643 {
1644  MockRepository mocks;
1646  auto &&ehlr = setup_ehlr(vmcs);
1647 
1648  ehlr.m_state_save->rcx = intel_x64::msrs::ia32_gs_base::addr;
1649  ehlr.m_state_save->rax = 0x8;
1650  ehlr.m_state_save->rdx = 0x9;
1651 
1652  RUN_UNITTEST_WITH_MOCKS(mocks, [&]
1653  {
1654  this->expect_no_exception([&]{ ehlr.dispatch(); });
1655 
1657  this->expect_true(g_value == 0x0000000900000008);
1658  this->expect_true(ehlr.m_state_save->rip == g_rip);
1659  });
1660 }
1661 
1662 void
1663 exit_handler_intel_x64_ut::test_vm_exit_reason_wrmsr_default()
1664 {
1665  MockRepository mocks;
1667  auto &&ehlr = setup_ehlr(vmcs);
1668 
1669  ehlr.m_state_save->rcx = 0x10;
1670  ehlr.m_state_save->rax = 0x9;
1671  ehlr.m_state_save->rdx = 0xA;
1672 
1673  RUN_UNITTEST_WITH_MOCKS(mocks, [&]
1674  {
1675  this->expect_no_exception([&]{ ehlr.dispatch(); });
1676  this->expect_true(g_msrs[0x10] = 0x0000000A00000009);
1677  this->expect_true(ehlr.m_state_save->rip == g_rip);
1678  });
1679 }
1680 
1681 void
1682 exit_handler_intel_x64_ut::test_vm_exit_failure_check()
1683 {
1684  MockRepository mocks;
1686  auto &&ehlr = setup_ehlr(vmcs);
1687 
1688  mocks.OnCallFunc(vmcs::check::all).Do(vmcs_check_all);
1689 
1690  RUN_UNITTEST_WITH_MOCKS(mocks, [&]
1691  {
1692  this->expect_no_exception([&]{ ehlr.dispatch(); });
1693  });
1694 }
1695 
1696 void
1697 exit_handler_intel_x64_ut::test_halt()
1698 {
1699  MockRepository mocks;
1701  auto &&ehlr = setup_ehlr(vmcs);
1702 
1703  RUN_UNITTEST_WITH_MOCKS(mocks, [&]
1704  {
1705  this->expect_no_exception([&]{ ehlr.halt(); });
1706  });
1707 }
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
Definition: constants.h:53
#define BF_VMCALL_FAILURE
Definition: error_codes.h:135
#define RUN_UNITTEST_WITH_MOCKS(a, b)
Definition: unittest.h:229
#define VMCALL_VERSION
#define VMCALL_IN_BUFFER_SIZE
Definition: constants.h:263
void __wbinvd(void) noexcept
vmcs::field_type g_field
#define ec_sign(a)
Definition: error_codes.h:35
#define USER_VERSION_PATCH
Definition: constants.h:61
#define expect_no_exception(f)
Definition: unittest.h:198
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
bool __vmread(uint64_t field, uint64_t *val) noexcept
virtual void promote()
virtual void resume()
auto setup_vmcs_halt(MockRepository &mocks, vmcs::value_type reason)
#define VMCALL_OUT_BUFFER_SIZE
Definition: constants.h:272
#define BAREFLANK_VERSION_PATCH
Definition: constants.h:45
constexpr const auto pt
Definition: mem_attr_x64.h:41
#define BF_VMCALL_SUCCESS
Definition: error_codes.h:134
#define BAREFLANK_VERSION_MINOR
Definition: constants.h:44
void uint64_t uint64_t uint64_t *rdx noexcept
virtual void map_4k(integer_pointer virt, integer_pointer phys, attr_type attr)
constexpr const auto addr
Definition: cpuid_x64.h:80
virtual void unmap(integer_pointer virt) noexcept
constexpr const auto mask
auto setup_vmcs_handled(MockRepository &mocks, vmcs::value_type reason)
#define USER_VERSION_MINOR
Definition: constants.h:57
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
virtual void load()
virtual void clear()
constexpr const auto addr
Definition: msrs_x64.h:50
constexpr const auto addr
bool __vmwrite(uint64_t field, uint64_t val) noexcept
constexpr const auto mask
vmcs::value_type g_value
constexpr const auto addr
#define BAREFLANK_VERSION_MAJOR
Definition: constants.h:43
void __cpuid(void *eax, void *ebx, void *ecx, void *edx) noexcept
virtual void free_map(pointer ptr) noexcept
state_save_intel_x64 g_state_save
Definition: cache_x64.h:31
#define expect_true(a)
vmcs::value_type g_exit_instruction_length
vmcs::value_type g_exit_qualification
#define VMCALL_MAGIC_NUMBER
uintptr_t g_rip
root_page_table_x64 * root_pt() noexcept