Index: /trunk/src/VBox/VMM/VMMR0/HMVMXR0.cpp
===================================================================
--- /trunk/src/VBox/VMM/VMMR0/HMVMXR0.cpp	(revision 45346)
+++ /trunk/src/VBox/VMM/VMMR0/HMVMXR0.cpp	(revision 45347)
@@ -5533,21 +5533,59 @@
     Log(("hmR0VmxLongJmpToRing3: rcExit=%d\n", rcExit));
 
+    int rc = hmR0VmxSaveGuestState(pVM, pVCpu, pMixedCtx);
+    AssertRC(rc);
+
+    /* Restore debug registers if necessary and resync on next R0 re-entry. */
+    if (CPUMIsGuestDebugStateActive(pVCpu))
+    {
+        CPUMR0SaveGuestDebugState(pVM, pVCpu, pMixedCtx, true /* save DR6 */);
+        pVCpu->hm.s.fContextUseFlags |= HM_CHANGED_GUEST_DEBUG;
+    }
+    else if (CPUMIsHyperDebugStateActive(pVCpu))
+    {
+        CPUMR0LoadHostDebugState(pVM, pVCpu);
+        pVCpu->hm.s.fContextUseFlags |= HM_CHANGED_GUEST_DEBUG;
+    }
+
+    STAM_COUNTER_INC(&pVCpu->hm.s.StatSwitchToR3);
+}
+
+
+/**
+ * An action requires us to go back to ring-3. This function does the necessary
+ * steps before we can safely return to ring-3. This is not the same as longjmps
+ * to ring-3, this is voluntary.
+ *
+ * @param   pVM         Pointer to the VM.
+ * @param   pVCpu       Pointer to the VMCPU.
+ * @param   pMixedCtx   Pointer to the guest-CPU context. The data may be
+ *                      out-of-sync. Make sure to update the required fields
+ *                      before using them.
+ * @param   rcExit      The reason for exiting to ring-3. Can be
+ *                      VINF_VMM_UNKNOWN_RING3_CALL.
+ */
+static void hmR0VmxExitToRing3(PVM pVM, PVMCPU pVCpu, PCPUMCTX pMixedCtx, int rcExit)
+{
+    Assert(pVM);
+    Assert(pVCpu);
+    Assert(pMixedCtx);
+    Assert(!RTThreadPreemptIsEnabled(NIL_RTTHREAD));
+
+    /* We want to see what the guest-state was before VM-entry, don't resync here, as we will never continue guest execution.*/
+    if (rcExit == VERR_VMX_INVALID_GUEST_STATE)
+        return;
+
+    /* Please, no longjumps here (any logging shouldn't flush jump back to ring-3). NO LOGGING BEFORE THIS POINT! */
+    VMMRZCallRing3Disable(pVCpu);
+    Log(("hmR0VmxExitToRing3: rcExit=%d\n", rcExit));
+
+    /* We need to do this only while truly exiting the "inner loop" back to ring-3 and -not- for any longjmp to ring3. */
+    hmR0VmxUpdateTRPMTrap(pVCpu);
+
+    /* Sync. the guest state. */
+    hmR0VmxLongJmpToRing3(pVM, pVCpu, pMixedCtx, rcExit);
+
     /* We're going back to ring-3, clear the flag that we need to go back to ring-3. */
     VMCPU_FF_CLEAR(pVCpu, VMCPU_FF_TO_R3);
-
-    int rc = hmR0VmxSaveGuestState(pVM, pVCpu, pMixedCtx);
-    AssertRC(rc);
-
-    /* Restore debug registers if necessary and resync on next R0 re-entry. */
-    if (CPUMIsGuestDebugStateActive(pVCpu))
-    {
-        CPUMR0SaveGuestDebugState(pVM, pVCpu, pMixedCtx, true /* save DR6 */);
-        pVCpu->hm.s.fContextUseFlags |= HM_CHANGED_GUEST_DEBUG;
-    }
-    else if (CPUMIsHyperDebugStateActive(pVCpu))
-    {
-        CPUMR0LoadHostDebugState(pVM, pVCpu);
-        pVCpu->hm.s.fContextUseFlags |= HM_CHANGED_GUEST_DEBUG;
-    }
 
     /* Signal changes to the recompiler. */
@@ -5565,42 +5603,4 @@
     else
         pVCpu->hm.s.fContextUseFlags |= HM_CHANGED_HOST_CONTEXT | HM_CHANGED_ALL_GUEST;
-
-    STAM_COUNTER_INC(&pVCpu->hm.s.StatSwitchToR3);
-}
-
-
-/**
- * An action requires us to go back to ring-3. This function does the necessary
- * steps before we can safely return to ring-3. This is not the same as longjmps
- * to ring-3, this is voluntary.
- *
- * @param   pVM         Pointer to the VM.
- * @param   pVCpu       Pointer to the VMCPU.
- * @param   pMixedCtx   Pointer to the guest-CPU context. The data may be
- *                      out-of-sync. Make sure to update the required fields
- *                      before using them.
- * @param   rcExit      The reason for exiting to ring-3. Can be
- *                      VINF_VMM_UNKNOWN_RING3_CALL.
- */
-static void hmR0VmxExitToRing3(PVM pVM, PVMCPU pVCpu, PCPUMCTX pMixedCtx, int rcExit)
-{
-    Assert(pVM);
-    Assert(pVCpu);
-    Assert(pMixedCtx);
-    Assert(!RTThreadPreemptIsEnabled(NIL_RTTHREAD));
-
-    /* We want to see what the guest-state was before VM-entry, don't resync here, as we will never continue guest execution.*/
-    if (rcExit == VERR_VMX_INVALID_GUEST_STATE)
-        return;
-
-    /* Please, no longjumps here (any logging shouldn't flush jump back to ring-3). NO LOGGING BEFORE THIS POINT! */
-    VMMRZCallRing3Disable(pVCpu);
-    Log(("hmR0VmxExitToRing3: rcExit=%d\n", rcExit));
-
-    /* We need to do this only while truly exiting the "inner loop" back to ring-3 and -not- for any longjmp to ring3. */
-    hmR0VmxUpdateTRPMTrap(pVCpu);
-
-    /* Sync. the rest of the state before going back to ring-3. */
-    hmR0VmxLongJmpToRing3(pVM, pVCpu, pMixedCtx, rcExit);
 
     VMMRZCallRing3Enable(pVCpu);
@@ -6387,5 +6387,5 @@
     int rc = VMXR0LoadGuestState(pVM, pVCpu, pMixedCtx);
     AssertRC(rc);
-    AssertMsg(pVCpu->hm.s.fContextUseFlags == 0, ("fContextUseFlags =%#x\n", pVCpu->hm.s.fContextUseFlags));
+    AssertMsg(!pVCpu->hm.s.fContextUseFlags, ("fContextUseFlags =%#x\n", pVCpu->hm.s.fContextUseFlags));
 
     /* Cache the TPR-shadow for checking on every VM-exit if it might have changed. */
@@ -6601,5 +6601,4 @@
 }
 
-/* Validates input parameters for VM-exit handler functions. Later change this to be debug builds only. */
 #ifdef DEBUG
 /* Is there some generic IPRT define for this that are not in Runtime/internal/\* ?? */
