Index: trunk/src/VBox/VMM/VMMAll/NEMAllNativeTemplate-win.cpp.h
===================================================================
--- trunk/src/VBox/VMM/VMMAll/NEMAllNativeTemplate-win.cpp.h	(revision 71223)
+++ trunk/src/VBox/VMM/VMMAll/NEMAllNativeTemplate-win.cpp.h	(revision 71224)
@@ -29,7 +29,4 @@
                 (a_Dst).fFlags   = CPUMSELREG_FLAGS_VALID; \
             } while (0)
-
-/** The CPUMCTX_EXTRN_XXX mask for IEM. */
-#define NEM_WIN_CPUMCTX_EXTRN_MASK_FOR_IEM      CPUMCTX_EXTRN_ALL
 
 
@@ -1178,5 +1175,8 @@
 }
 
-#ifdef IN_RING0
+
+#ifdef NEM_WIN_USE_OUR_OWN_RUN_API
+
+# ifdef IN_RING0
 /**
  * Wrapper around nemR0WinImportState that converts VERR_NEM_CHANGE_PGM_MODE and
@@ -1207,5 +1207,5 @@
     AssertMsgFailedReturn(("%s/%u: nemR0WinImportState failed: %Rrc\n", pszCaller, pGVCpu->idCpu, rc), rc);
 }
-#endif /* IN_RING0 */
+# endif /* IN_RING0 */
 
 /**
@@ -1290,13 +1290,13 @@
     nemHCWinCopyStateFromX64Header(pCtx, &pMsg->Header);
     VBOXSTRICTRC rcStrict;
-#ifdef IN_RING0
+# ifdef IN_RING0
     rcStrict = nemR0WinImportStateStrict(pGVCpu->pGVM, pGVCpu, pCtx, NEM_WIN_CPUMCTX_EXTRN_MASK_FOR_IEM, "MemExit");
     if (rcStrict != VINF_SUCCESS)
         return rcStrict;
-#else
+# else
     rc = nemHCWinCopyStateFromHyperV(pVM, pVCpu, pCtx, NEM_WIN_CPUMCTX_EXTRN_MASK_FOR_IEM);
     AssertRCReturn(rc, rc);
     NOREF(pGVCpu);
-#endif
+# endif
 
     if (pMsg->InstructionByteCount > 0)
@@ -1400,13 +1400,13 @@
         pCtx->rdi = pMsg->Rdi;
         pCtx->rsi = pMsg->Rsi;
-#ifdef IN_RING0
+# ifdef IN_RING0
         rcStrict = nemR0WinImportStateStrict(pGVCpu->pGVM, pGVCpu, pCtx, NEM_WIN_CPUMCTX_EXTRN_MASK_FOR_IEM, "IOExit");
         if (rcStrict != VINF_SUCCESS)
             return rcStrict;
-#else
+# else
         int rc = nemHCWinCopyStateFromHyperV(pVM, pVCpu, pCtx, NEM_WIN_CPUMCTX_EXTRN_MASK_FOR_IEM);
         AssertRCReturn(rc, rc);
         RT_NOREF(pGVCpu);
-#endif
+# endif
 
         Log4(("IOExit/%u: %04x:%08RX64: %s%s %#x LB %u (emulating)\n",
@@ -1528,5 +1528,5 @@
      * does another VM exit.
      */
-#ifdef IN_RING0
+# ifdef IN_RING0
     pVCpu->nem.s.uIoCtlBuf.idCpu = pGVCpu->idCpu;
     NTSTATUS rcNt = nemR0NtPerformIoControl(pGVM, pGVM->nem.s.IoCtlStopVirtualProcessor.uFunction,
@@ -1538,5 +1538,5 @@
         return rcStrict;
     }
-#else
+# else
     BOOL fRet = VidStopVirtualProcessor(pVM->nem.s.hPartitionDevice, pVCpu->idCpu);
     if (fRet)
@@ -1546,17 +1546,17 @@
     }
     RT_NOREF(pGVM, pGVCpu);
-#endif
+# endif
 
     /*
      * Dang. The CPU stopped by itself and we got a couple of message to deal with.
      */
-#ifdef IN_RING0
+# ifdef IN_RING0
     AssertLogRelMsgReturn(rcNt == ERROR_VID_STOP_PENDING, ("rcNt=%#x\n", rcNt),
                           RT_SUCCESS(rcStrict) ?  VERR_INTERNAL_ERROR_3 : rcStrict);
-#else
+# else
     DWORD dwErr = RTNtLastErrorValue();
     AssertLogRelMsgReturn(dwErr == ERROR_VID_STOP_PENDING, ("dwErr=%#u (%#x)\n", dwErr, dwErr),
                           RT_SUCCESS(rcStrict) ?  VERR_INTERNAL_ERROR_3 : rcStrict);
-#endif
+# endif
     Log8(("nemHCWinStopCpu: Stopping CPU pending...\n"));
 
@@ -1565,5 +1565,5 @@
      * Note! We can safely ASSUME that rcStrict isn't an important information one.
      */
-#ifdef IN_RING0
+# ifdef IN_RING0
     pVCpu->nem.s.uIoCtlBuf.MsgSlotHandleAndGetNext.iCpu     = pGVCpu->idCpu;
     pVCpu->nem.s.uIoCtlBuf.MsgSlotHandleAndGetNext.fFlags   = VID_MSHAGN_F_GET_NEXT_MESSAGE;
@@ -1575,10 +1575,10 @@
     AssertLogRelMsgReturn(NT_SUCCESS(rcNt), ("1st VidMessageSlotHandleAndGetNext after ERROR_VID_STOP_PENDING failed: %#x\n", rcNt),
                           RT_SUCCESS(rcStrict) ? VERR_INTERNAL_ERROR_3 : rcStrict);
-#else
+# else
     BOOL fWait = g_pfnVidMessageSlotHandleAndGetNext(pVM->nem.s.hPartitionDevice, pVCpu->idCpu,
                                                      VID_MSHAGN_F_GET_NEXT_MESSAGE, 30000 /*ms*/);
     AssertLogRelMsgReturn(fWait, ("1st VidMessageSlotHandleAndGetNext after ERROR_VID_STOP_PENDING failed: %u\n", RTNtLastErrorValue()),
                           RT_SUCCESS(rcStrict) ? VERR_INTERNAL_ERROR_3 : rcStrict);
-#endif
+# endif
 
     /* It should be a hypervisor message and definitely not a stop request completed message. */
@@ -1597,5 +1597,5 @@
      * that as handled too.  CPU is back into fully stopped stated then.
      */
-#ifdef IN_RING0
+# ifdef IN_RING0
     pVCpu->nem.s.uIoCtlBuf.MsgSlotHandleAndGetNext.iCpu     = pGVCpu->idCpu;
     pVCpu->nem.s.uIoCtlBuf.MsgSlotHandleAndGetNext.fFlags   = VID_MSHAGN_F_HANDLE_MESSAGE | VID_MSHAGN_F_GET_NEXT_MESSAGE;
@@ -1607,10 +1607,10 @@
     AssertLogRelMsgReturn(NT_SUCCESS(rcNt), ("2st VidMessageSlotHandleAndGetNext after ERROR_VID_STOP_PENDING failed: %#x\n", rcNt),
                           RT_SUCCESS(rcStrict) ? VERR_INTERNAL_ERROR_3 : rcStrict);
-#else
+# else
     fWait = g_pfnVidMessageSlotHandleAndGetNext(pVM->nem.s.hPartitionDevice, pVCpu->idCpu,
                                                 VID_MSHAGN_F_HANDLE_MESSAGE | VID_MSHAGN_F_GET_NEXT_MESSAGE, 30000 /*ms*/);
     AssertLogRelMsgReturn(fWait, ("2nd VidMessageSlotHandleAndGetNext after ERROR_VID_STOP_PENDING failed: %u\n", RTNtLastErrorValue()),
                           RT_SUCCESS(rcStrict) ? VERR_INTERNAL_ERROR_3 : rcStrict);
-#endif
+# endif
 
     /* It should be a stop request completed message. */
@@ -1622,5 +1622,5 @@
 
     /* Mark this as handled. */
-#ifdef IN_RING0
+# ifdef IN_RING0
     pVCpu->nem.s.uIoCtlBuf.MsgSlotHandleAndGetNext.iCpu     = pGVCpu->idCpu;
     pVCpu->nem.s.uIoCtlBuf.MsgSlotHandleAndGetNext.fFlags   = VID_MSHAGN_F_HANDLE_MESSAGE;
@@ -1632,9 +1632,9 @@
     AssertLogRelMsgReturn(NT_SUCCESS(rcNt), ("3rd VidMessageSlotHandleAndGetNext after ERROR_VID_STOP_PENDING failed: %#x\n", rcNt),
                           RT_SUCCESS(rcStrict) ? VERR_INTERNAL_ERROR_3 : rcStrict);
-#else
+# else
     fWait = g_pfnVidMessageSlotHandleAndGetNext(pVM->nem.s.hPartitionDevice, pVCpu->idCpu, VID_MSHAGN_F_HANDLE_MESSAGE, 30000 /*ms*/);
     AssertLogRelMsgReturn(fWait, ("3rd VidMessageSlotHandleAndGetNext after ERROR_VID_STOP_PENDING failed: %u\n", RTNtLastErrorValue()),
                           RT_SUCCESS(rcStrict) ? VERR_INTERNAL_ERROR_3 : rcStrict);
-#endif
+# endif
     Log8(("nemHCWinStopCpu: Stopped the CPU (rcStrict=%Rrc)\n", VBOXSTRICTRC_VAL(rcStrict) ));
     return rcStrict;
@@ -1646,8 +1646,8 @@
     PCPUMCTX pCtx = CPUMQueryGuestCtxPtr(pVCpu);
     LogFlow(("NEM/%u: %04x:%08RX64 efl=%#08RX64 <=\n", pVCpu->idCpu, pCtx->cs.Sel, pCtx->rip, pCtx->rflags));
-#ifdef LOG_ENABLED
+# ifdef LOG_ENABLED
     if (LogIs3Enabled())
         nemHCWinLogState(pVM, pVCpu);
-#endif
+# endif
 
     /*
@@ -1668,10 +1668,10 @@
         if ((pCtx->fExtrn & (CPUMCTX_EXTRN_ALL | CPUMCTX_EXTRN_NEM_WIN_MASK)) != (CPUMCTX_EXTRN_ALL | CPUMCTX_EXTRN_NEM_WIN_MASK))
         {
-#ifdef IN_RING0
+# ifdef IN_RING0
             int rc2 = nemR0WinExportState(pGVM, pGVCpu, pCtx);
-#else
+# else
             int rc2 = nemHCWinCopyStateToHyperV(pVM, pVCpu, pCtx);
             RT_NOREF(pGVM, pGVCpu);
-#endif
+# endif
             AssertRCReturn(rc2, rc2);
         }
@@ -1687,5 +1687,5 @@
             else
             {
-#ifdef IN_RING0
+# ifdef IN_RING0
                 pVCpu->nem.s.uIoCtlBuf.idCpu = pGVCpu->idCpu;
                 NTSTATUS rcNt = nemR0NtPerformIoControl(pGVM, pGVM->nem.s.IoCtlStartVirtualProcessor.uFunction,
@@ -1695,10 +1695,10 @@
                 AssertLogRelMsgReturn(NT_SUCCESS(rcNt), ("VidStartVirtualProcessor failed for CPU #%u: %#x\n", pGVCpu->idCpu, rcNt),
                                       VERR_INTERNAL_ERROR_3);
-#else
+# else
                 AssertLogRelMsgReturn(g_pfnVidStartVirtualProcessor(pVM->nem.s.hPartitionDevice, pVCpu->idCpu),
                                       ("VidStartVirtualProcessor failed for CPU #%u: %u (%#x, rcNt=%#x)\n",
                                        pVCpu->idCpu, RTNtLastErrorValue(), RTNtLastErrorValue(), RTNtLastStatusValue()),
                                       VERR_INTERNAL_ERROR_3);
-#endif
+# endif
                 pVCpu->nem.s.fHandleAndGetFlags = VID_MSHAGN_F_GET_NEXT_MESSAGE;
             }
@@ -1706,5 +1706,5 @@
             if (VMCPU_CMPXCHG_STATE(pVCpu, VMCPUSTATE_STARTED_EXEC_NEM_WAIT, VMCPUSTATE_STARTED))
             {
-#ifdef IN_RING0
+# ifdef IN_RING0
                 pVCpu->nem.s.uIoCtlBuf.MsgSlotHandleAndGetNext.iCpu     = pGVCpu->idCpu;
                 pVCpu->nem.s.uIoCtlBuf.MsgSlotHandleAndGetNext.fFlags   = pVCpu->nem.s.fHandleAndGetFlags;
@@ -1716,10 +1716,10 @@
                 VMCPU_CMPXCHG_STATE(pVCpu, VMCPUSTATE_STARTED, VMCPUSTATE_STARTED_EXEC_NEM_WAIT);
                 if (rcNt == STATUS_SUCCESS)
-#else
+# else
                 BOOL fRet = VidMessageSlotHandleAndGetNext(pVM->nem.s.hPartitionDevice, pVCpu->idCpu,
                                                            pVCpu->nem.s.fHandleAndGetFlags, cMillies);
                 VMCPU_CMPXCHG_STATE(pVCpu, VMCPUSTATE_STARTED, VMCPUSTATE_STARTED_EXEC_NEM_WAIT);
                 if (fRet)
-#endif
+# endif
                 {
                     /*
@@ -1741,7 +1741,7 @@
                        so after NtAlertThread we end up here with a STATUS_TIMEOUT.  And yeah,
                        the error code conversion is into WAIT_XXX, i.e. NT status codes. */
-#ifndef IN_RING0
+# ifndef IN_RING0
                     DWORD rcNt = GetLastError();
-#endif
+# endif
                     LogFlow(("NEM/%u: VidMessageSlotHandleAndGetNext -> %#x\n", pVCpu->idCpu, rcNt));
                     AssertLogRelMsgReturn(   rcNt == STATUS_TIMEOUT
@@ -1788,5 +1788,5 @@
     if (pCtx->fExtrn & (CPUMCTX_EXTRN_ALL | (CPUMCTX_EXTRN_NEM_WIN_MASK & ~CPUMCTX_EXTRN_NEM_WIN_EVENT_INJECT)))
     {
-#ifdef IN_RING0
+# ifdef IN_RING0
         int rc2 = nemR0WinImportState(pGVM, pGVCpu, pCtx, CPUMCTX_EXTRN_ALL | CPUMCTX_EXTRN_NEM_WIN_MASK);
         if (RT_SUCCESS(rc2))
@@ -1803,9 +1803,9 @@
             }
         }
-#else
+# else
         int rc2 = nemHCWinCopyStateFromHyperV(pVM, pVCpu, pCtx, CPUMCTX_EXTRN_ALL | CPUMCTX_EXTRN_NEM_WIN_MASK);
         if (RT_SUCCESS(rc2))
             pCtx->fExtrn = 0;
-#endif
+# endif
         else if (RT_SUCCESS(rcStrict))
             rcStrict = rc2;
@@ -1819,4 +1819,5 @@
 }
 
+#endif /* NEM_WIN_USE_OUR_OWN_RUN_API */
 
 
