diff options
author | ionescu007 <aionescu+git@gmail.com> | 2016-08-29 07:56:18 +0300 |
---|---|---|
committer | ionescu007 <aionescu+git@gmail.com> | 2016-08-29 07:56:18 +0300 |
commit | 75ed51f8f7f8d2b29b1407515d1f0a633a4c0482 (patch) | |
tree | 3a42fa88be1700d75492ee6db09592fcca84f3af | |
parent | 77fb2e9985648546e3f6824f6a2b8b75f1b82586 (diff) |
WIP Cleaner way to launch.
-rw-r--r-- | shv.h | 5 | ||||
-rw-r--r-- | shvvmx.c | 7 | ||||
-rw-r--r-- | shvvmxhv.c | 2 | ||||
-rw-r--r-- | shvvp.c | 53 |
4 files changed, 35 insertions, 32 deletions
@@ -143,6 +143,11 @@ ShvVmxEptInitialize ( _In_ PSHV_VP_DATA VpData ); +DECLSPEC_NORETURN +VOID +ShvVpRestoreAfterLaunch ( + VOID + ); typedef struct _SHV_DPC_CONTEXT { @@ -375,7 +375,7 @@ ShvVmxSetupVmcsForVp ( // to inside of ShvVpInitialize. // __vmx_vmwrite(GUEST_RSP, context->Rsp); - __vmx_vmwrite(GUEST_RIP, context->Rip); + __vmx_vmwrite(GUEST_RIP, (ULONG_PTR)ShvVpRestoreAfterLaunch); __vmx_vmwrite(GUEST_RFLAGS, context->EFlags); // @@ -464,11 +464,6 @@ ShvVmxLaunchOnVp ( // Initialize the VMCS, both guest and host state. // ShvVmxSetupVmcsForVp(VpData); - - // - // Record that VMX is now enabled - // - VpData->VmxEnabled = 1; // // Launch the VMCS, based on the guest data that was loaded into the @@ -16,7 +16,7 @@ Author: Environment: - Hypervisor mode only, IRQL DIRQL_MAX + Hypervisor mode only, IRQL MAX_IRQL --*/ @@ -79,6 +79,29 @@ ShvCaptureSpecialRegisters ( _sldt(&SpecialRegisters->Ldtr); } +DECLSPEC_NORETURN +VOID +ShvVpRestoreAfterLaunch ( + VOID + ) +{ + PSHV_VP_DATA vpData = ShvGlobalData[KeGetCurrentProcessorNumberEx(NULL)]; + + // + // Record that VMX is now enabled + // + vpData->VmxEnabled = 1; + + // + // And finally, restore the context, so that all register and stack + // state is finally restored. Note that by continuing to reference the + // per-VP data this way, the compiler will continue to generate non- + // optimized accesses, guaranteeing that no previous register state + // will be used. + // + RtlRestoreContext(&vpData->ContextFrame, NULL); +} + VOID ShvVpInitialize ( _In_ PSHV_VP_DATA Data, @@ -114,34 +137,14 @@ ShvVpInitialize ( // variable combined with an API call, we also make sure that the compiler // will not optimize this access in any way, even on LTGC/Ox builds. // - if (ShvGlobalData[KeGetCurrentProcessorNumberEx(NULL)]->VmxEnabled == 1) + if (ShvGlobalData[KeGetCurrentProcessorNumberEx(NULL)]->VmxEnabled == 0) { // - // We now indicate that the VM has launched, and that we are about to - // restore the GPRs back to their original values. This will have the - // effect of putting us yet *AGAIN* at the previous line of code, but - // this time the value of VmxEnabled will be two, bypassing the if and - // else if checks. - // - ShvGlobalData[KeGetCurrentProcessorNumberEx(NULL)]->VmxEnabled = 2; - - // - // And finally, restore the context, so that all register and stack - // state is finally restored. Note that by continuing to reference the - // per-VP data this way, the compiler will continue to generate non- - // optimized accesses, guaranteeing that no previous register state - // will be used. + // If we are in this branch comparison, it means that we have not yet + // attempted to launch the VM, nor that we have launched it. In other + // words, this is the first time in ShvVpInitialize. Because of this, + // we are free to use all register state, as it is ours to use. // - RtlRestoreContext(&ShvGlobalData[KeGetCurrentProcessorNumberEx(NULL)]->ContextFrame, NULL); - } - // - // If we are in this branch comparison, it means that we have not yet - // attempted to launch the VM, nor that we have launched it. In other - // words, this is the first time in ShvVpInitialize. Because of this, - // we are free to use all register state, as it is ours to use. - // - else if (Data->VmxEnabled == 0) - { // // First, capture the value of the PML4 for the SYSTEM process, so that // all virtual processors, regardless of which process the current LP |