| 372 | } |
| 373 | |
| 374 | extern "C" VMM_STATUS SvmVmexitHandler(PRIVATE_VM_DATA* Private, GUEST_CONTEXT* Context) |
| 375 | { |
| 376 | // Load the host state: |
| 377 | __svm_vmload(reinterpret_cast<size_t>(Private->VmmStack.Layout.InitialStack.HostVmcbPa)); |
| 378 | |
| 379 | // Restore the guest's RAX that was overwritten by host's RAX on #VMEXIT: |
| 380 | Context->Rax = Private->Guest.StateSaveArea.Rax; |
| 381 | |
| 382 | VMM_STATUS Status = VMM_STATUS::VMM_CONTINUE; |
| 383 | switch (Private->Guest.ControlArea.ExitCode) |
| 384 | { |
| 385 | case VMEXIT_CPUID: |
| 386 | { |
| 387 | CPUID_REGS Regs = {}; |
| 388 | int Function = static_cast<int>(Context->Rax); |
| 389 | int SubLeaf = static_cast<int>(Context->Rcx); |
| 390 | __cpuidex(Regs.Raw, Function, SubLeaf); |
| 391 | |
| 392 | switch (Function) { |
| 393 | case CPUID_VMM_SHUTDOWN: |
| 394 | { |
| 395 | // Shutdown was triggered: |
| 396 | Status = VMM_STATUS::VMM_SHUTDOWN; |
| 397 | break; |
| 398 | } |
| 399 | case CPUID::Generic::CPUID_MAXIMUM_FUNCTION_NUMBER_AND_VENDOR_ID: |
| 400 | { |
| 401 | // Vendor = 'Hyper-Bridge' as RBX + RDX + RCX: |
| 402 | Context->Rax = Regs.Regs.Eax; |
| 403 | GetHvCpuName(Context->Rbx, Context->Rcx, Context->Rdx); |
| 404 | break; |
| 405 | } |
| 406 | default: |
| 407 | { |
| 408 | Context->Rax = Regs.Regs.Eax; |
| 409 | Context->Rbx = Regs.Regs.Ebx; |
| 410 | Context->Rcx = Regs.Regs.Ecx; |
| 411 | Context->Rdx = Regs.Regs.Edx; |
| 412 | break; |
| 413 | } |
| 414 | } |
| 415 | break; |
| 416 | } |
| 417 | case VMEXIT_MSR: |
| 418 | { |
| 419 | if ((Context->Rcx & MAXUINT32) == static_cast<unsigned int>(AMD_MSR::MSR_EFER) && Private->Guest.ControlArea.ExitInfo1) |
| 420 | { |
| 421 | EFER Efer = {}; |
| 422 | Efer.Value = ((Context->Rdx & MAXUINT32) << 32) | (Context->Rax & MAXUINT32); |
| 423 | if (!Efer.Bitmap.SecureVirtualMachineEnable) |
| 424 | { |
| 425 | InjectEvent(&Private->Guest, 13, 3, 0); // #GP (Vector = 13, Type = Exception) |
| 426 | break; |
| 427 | } |
| 428 | Private->Guest.StateSaveArea.Efer = Efer.Value; |
| 429 | } |
| 430 | break; |
| 431 | } |
nothing calls this directly
no test coverage detected