Lines Matching defs:pVM

84 static DECLCALLBACK(int) emR3Save(PVM pVM, PSSMHANDLE pSSM);
85 static DECLCALLBACK(int) emR3Load(PVM pVM, PSSMHANDLE pSSM, uint32_t uVersion, uint32_t uPass);
89 static VBOXSTRICTRC emR3Debug(PVM pVM, PVMCPU pVCpu, VBOXSTRICTRC rc);
90 static int emR3RemStep(PVM pVM, PVMCPU pVCpu);
91 static int emR3RemExecute(PVM pVM, PVMCPU pVCpu, bool *pfFFDone);
92 int emR3HighPriorityPostForcedActions(PVM pVM, PVMCPU pVCpu, int rc);
99 * @param pVM Pointer to the VM.
101 VMMR3_INT_DECL(int) EMR3Init(PVM pVM)
108 AssertCompile(sizeof(pVM->em.s) <= sizeof(pVM->em.padding));
109 AssertCompile(sizeof(pVM->aCpus[0].em.s.u.FatalLongJump) <= sizeof(pVM->aCpus[0].em.s.u.achPaddingFatalLongJump));
114 pVM->em.s.offVM = RT_OFFSETOF(VM, em.s);
115 PCFGMNODE pCfgRoot = CFGMR3GetRoot(pVM);
121 pVM->fRecompileUser = !fEnabled;
125 pVM->fRecompileSupervisor = !fEnabled;
128 rc = CFGMR3QueryBoolDef(pCfgRoot, "RawR1Enabled", &pVM->fRawRing1Enabled, false);
131 pVM->fRawRing1Enabled = false; /* Disabled by default. */
134 rc = CFGMR3QueryBoolDef(pCfgEM, "IemExecutesAll", &pVM->em.s.fIemExecutesAll, false);
139 pVM->em.s.fGuruOnTripleFault = !fEnabled;
140 if (!pVM->em.s.fGuruOnTripleFault && pVM->cCpus > 1)
143 pVM->em.s.fGuruOnTripleFault = true;
147 pVM->fRecompileUser, pVM->fRecompileSupervisor, pVM->fRawRing1Enabled, pVM->em.s.fIemExecutesAll, pVM->em.s.fGuruOnTripleFault));
154 rc = PDMR3CritSectInit(pVM, &pVM->em.s.CritSectREM, RT_SRC_POS, "EM-REM");
161 rc = SSMR3RegisterInternal(pVM, "em", 0, EM_SAVED_STATE_VERSION, 16,
168 for (VMCPUID i = 0; i < pVM->cCpus; i++)
170 PVMCPU pVCpu = &pVM->aCpus[i];
178 if (!HMIsEnabled(pVM))
180 pVCpu->em.s.pPatmGCState = PATMR3QueryGCStateHC(pVM);
189 rc = STAMR3RegisterF(pVM, a, STAMTYPE_COUNTER, STAMVISIBILITY_ALWAYS, STAMUNIT_OCCURENCES, c, b, i); \
193 rc = STAMR3RegisterF(pVM, a, STAMTYPE_COUNTER, STAMVISIBILITY_USED, STAMUNIT_OCCURENCES, c, b, i); \
197 rc = STAMR3RegisterF(pVM, a, STAMTYPE_PROFILE, STAMVISIBILITY_ALWAYS, STAMUNIT_TICKS_PER_CALL, c, b, i); \
201 rc = STAMR3RegisterF(pVM, a, STAMTYPE_PROFILE_ADV, STAMVISIBILITY_ALWAYS, STAMUNIT_TICKS_PER_CALL, c, b, i); \
209 rc = MMHyperAlloc(pVM, sizeof(*pStats), 0, MM_TAG_EM, (void **)&pStats);
214 pVCpu->em.s.pStatsR0 = MMHyperR3ToR0(pVM, pStats);
215 pVCpu->em.s.pStatsRC = MMHyperR3ToRC(pVM, pStats);
448 emR3InitDbg(pVM);
458 * @param pVM Pointer to the VM.
460 VMMR3_INT_DECL(void) EMR3Relocate(PVM pVM)
463 for (VMCPUID i = 0; i < pVM->cCpus; i++)
465 PVMCPU pVCpu = &pVM->aCpus[i];
467 pVCpu->em.s.pStatsRC = MMHyperR3ToRC(pVM, pVCpu->em.s.pStatsR3);
497 * @param pVM Pointer to the VM.
499 VMMR3_INT_DECL(void) EMR3Reset(PVM pVM)
502 for (VMCPUID i = 0; i < pVM->cCpus; i++)
503 EMR3ResetCpu(&pVM->aCpus[i]);
514 * @param pVM Pointer to the VM.
516 VMMR3_INT_DECL(int) EMR3Term(PVM pVM)
518 AssertMsg(pVM->em.s.offVM, ("bad init order!\n"));
521 PDMR3CritSectDelete(&pVM->em.s.CritSectREM);
531 * @param pVM Pointer to the VM.
534 static DECLCALLBACK(int) emR3Save(PVM pVM, PSSMHANDLE pSSM)
536 for (VMCPUID i = 0; i < pVM->cCpus; i++)
538 PVMCPU pVCpu = &pVM->aCpus[i];
570 * @param pVM Pointer to the VM.
575 static DECLCALLBACK(int) emR3Load(PVM pVM, PSSMHANDLE pSSM, uint32_t uVersion, uint32_t uPass)
591 for (VMCPUID i = 0; i < pVM->cCpus; i++)
593 PVMCPU pVCpu = &pVM->aCpus[i];
645 static DECLCALLBACK(VBOXSTRICTRC) emR3SetExecutionPolicy(PVM pVM, PVMCPU pVCpu, void *pvUser)
656 pVM->fRecompileSupervisor = pArgs->fEnforce;
659 pVM->fRecompileUser = pArgs->fEnforce;
662 pVM->em.s.fIemExecutesAll = pArgs->fEnforce;
668 pVM->fRecompileUser, pVM->fRecompileSupervisor, pVM->em.s.fIemExecutesAll));
701 VM_ASSERT_VALID_EXT_RETURN(pUVM->pVM, VERR_INVALID_VM_HANDLE);
705 return VMMR3EmtRendezvous(pUVM->pVM, VMMEMTRENDEZVOUS_FLAGS_TYPE_DESCENDING, emR3SetExecutionPolicy, &Args);
722 PVM pVM = pUVM->pVM;
723 VM_ASSERT_VALID_EXT_RETURN(pVM, VERR_INVALID_VM_HANDLE);
729 *pfEnforced = pVM->fRecompileSupervisor;
732 *pfEnforced = pVM->fRecompileUser;
735 *pfEnforced = pVM->em.s.fIemExecutesAll;
799 * @param pVM Pointer to the VM.
803 static VBOXSTRICTRC emR3Debug(PVM pVM, PVMCPU pVCpu, VBOXSTRICTRC rc)
823 rc = emR3RawStep(pVM, pVCpu);
828 rc = EMR3HmSingleInstruction(pVM, pVCpu, 0 /*fFlags*/);
831 rc = emR3RemStep(pVM, pVCpu);
845 rc = DBGFR3Event(pVM, DBGFEVENT_STEPPED);
849 rc = DBGFR3EventBreakpoint(pVM, DBGFEVENT_BREAKPOINT);
853 rc = DBGFR3EventSrc(pVM, DBGFEVENT_DEV_STOP, NULL, 0, NULL, NULL);
857 rc = DBGFR3Event(pVM, DBGFEVENT_STEPPED_HYPER);
861 rc = DBGFR3EventBreakpoint(pVM, DBGFEVENT_BREAKPOINT_HYPER);
865 RTPrintf("\nVINF_EM_DBG_HYPER_ASSERTION:\n%s%s\n", VMMR3GetRZAssertMsg1(pVM), VMMR3GetRZAssertMsg2(pVM));
867 rc = DBGFR3EventAssertion(pVM, DBGFEVENT_ASSERTION_HYPER, VMMR3GetRZAssertMsg1(pVM), VMMR3GetRZAssertMsg2(pVM));
874 rc = DBGFR3EventSrc(pVM, DBGFEVENT_FATAL_ERROR, "VERR_VMM_RING0_ASSERTION", 0, NULL, NULL);
877 rc = DBGFR3EventSrc(pVM, DBGFEVENT_DEV_STOP, "VERR_REM_TOO_MANY_TRAPS", 0, NULL, NULL);
883 rc = DBGFR3Event(pVM, DBGFEVENT_FATAL_ERROR);
921 rc = emR3RawResumeHyper(pVM, pVCpu);
995 * @param pVM Pointer to the VM.
998 static int emR3RemStep(PVM pVM, PVMCPU pVCpu)
1003 EMRemLock(pVM);
1008 int rc = REMR3State(pVM, pVCpu);
1011 rc = REMR3Step(pVM, pVCpu);
1012 REMR3StateBack(pVM, pVCpu);
1014 EMRemUnlock(pVM);
1017 int rc = VBOXSTRICTRC_TODO(IEMExecOne(pVCpu)); NOREF(pVM);
1030 * @param pVM Pointer to the VM.
1033 DECLINLINE(bool) emR3RemExecuteSyncBack(PVM pVM, PVMCPU pVCpu)
1037 REMR3StateBack(pVM, pVCpu);
1040 EMRemUnlock(pVM);
1055 * @param pVM Pointer to the VM.
1061 static int emR3RemExecute(PVM pVM, PVMCPU pVCpu, bool *pfFFDone)
1076 || !MMHyperIsInsideArea(pVM, CPUMGetGuestEIP(pVCpu)), /** @todo @bugref{1419} - get flat address. */
1100 EMRemLock(pVM);
1105 if (pVM->em.s.idLastRemCpu != pVCpu->idCpu)
1107 REMFlushTBs(pVM);
1110 pVM->em.s.idLastRemCpu = pVCpu->idCpu;
1112 rc = REMR3State(pVM, pVCpu);
1123 if ( VM_FF_IS_PENDING(pVM, VM_FF_REQUEST | VM_FF_PDM_QUEUES | VM_FF_DBGF | VM_FF_CHECK_VM_STATE | VM_FF_RESET)
1126 LogFlow(("emR3RemExecute: Skipping run, because FF is set. %#x\n", pVM->fGlobalForcedActions));
1135 if (RT_LIKELY(emR3IsExecutionAllowed(pVM, pVCpu)))
1139 rc = REMR3Run(pVM, pVCpu);
1158 if ( VM_FF_IS_PENDING(pVM, VM_FF_HIGH_PRIORITY_POST_MASK)
1162 fInREMState = emR3RemExecuteSyncBack(pVM, pVCpu);
1164 rc = emR3HighPriorityPostForcedActions(pVM, pVCpu, rc);
1193 TMTimerPollVoid(pVM, pVCpu);
1196 if ( VM_FF_IS_PENDING(pVM, VM_FF_ALL_REM_MASK)
1204 fInREMState = emR3RemExecuteSyncBack(pVM, pVCpu);
1207 rc = emR3ForcedActions(pVM, pVCpu, rc);
1226 fInREMState = emR3RemExecuteSyncBack(pVM, pVCpu);
1236 int emR3SingleStepExecRem(PVM pVM, PVMCPU pVCpu, uint32_t cIterations)
1247 emR3RemStep(pVM, pVCpu);
1248 if (emR3Reschedule(pVM, pVCpu, pVCpu->em.s.pCtx) != EMSTATE_REM)
1265 * @param pVM The cross context VM structure.
1271 static VBOXSTRICTRC emR3ExecuteIemThenRem(PVM pVM, PVMCPU pVCpu, bool *pfFFDone)
1295 EMSTATE enmNewState = emR3Reschedule(pVM, pVCpu, pVCpu->em.s.pCtx);
1308 if ( VM_FF_IS_PENDING(pVM, VM_FF_ALL_REM_MASK)
1326 * @param pVM Pointer to the VM.
1330 EMSTATE emR3Reschedule(PVM pVM, PVMCPU pVCpu, PCPUMCTX pCtx)
1347 if (pVM->em.s.fIemExecutesAll)
1355 if (HMIsEnabled(pVM))
1360 if ( EMIsHwVirtExecutionEnabled(pVM)
1361 && HMR3CanExecuteGuest(pVM, pCtx))
1417 if (!EMIsRawRing3Enabled(pVM))
1426 if (!(u32CR0 & X86_CR0_WP) && EMIsRawRing0Enabled(pVM))
1434 if (!EMIsRawRing0Enabled(pVM))
1437 if (EMIsRawRing1Enabled(pVM))
1470 if (PATMShouldUseRawMode(pVM, (RTGCPTR)pCtx->eip))
1551 * @param pVM Pointer to the VM.
1555 int emR3HighPriorityPostForcedActions(PVM pVM, PVMCPU pVCpu, int rc)
1557 VBOXVMM_EM_FF_HIGH(pVCpu, pVM->fGlobalForcedActions, pVCpu->fLocalForcedActions, rc);
1588 CSAMR3DoPendingAction(pVM, pVCpu);
1591 if (VM_FF_IS_PENDING(pVM, VM_FF_PGM_NO_MEMORY))
1616 * @param pVM Pointer to the VM.
1621 int emR3ForcedActions(PVM pVM, PVMCPU pVCpu, int rc)
1636 VBOXVMM_EM_FF_ALL(pVCpu, pVM->fGlobalForcedActions, pVCpu->fLocalForcedActions, rc);
1641 if ( VM_FF_IS_PENDING(pVM, VM_FF_NORMAL_PRIORITY_POST_MASK)
1647 if (VM_FF_IS_PENDING(pVM, VM_FF_EMT_RENDEZVOUS))
1649 rc2 = VMMR3EmtRendezvousFF(pVM, pVCpu);
1667 if (VM_FF_IS_PENDING(pVM, VM_FF_CHECK_VM_STATE))
1669 VMSTATE enmState = VMR3GetState(pVM);
1691 if (VM_FF_IS_PENDING(pVM, VM_FF_DBGF))
1693 rc2 = DBGFR3VMMForcedAction(pVM);
1700 if (VM_FF_TEST_AND_CLEAR(pVM, VM_FF_RESET))
1702 rc2 = VMR3Reset(pVM->pUVM);
1710 if ( !VM_FF_IS_PENDING(pVM, VM_FF_PGM_NO_MEMORY)
1718 CSAMR3CheckCodeEx(pVM, pCtx, pCtx->eip);
1726 if (VM_FF_IS_PENDING(pVM, VM_FF_PGM_NO_MEMORY))
1728 rc2 = PGMR3PhysAllocateHandyPages(pVM);
1743 if (VM_FF_IS_PENDING_EXCEPT(pVM, VM_FF_NORMAL_PRIORITY_MASK, VM_FF_PGM_NO_MEMORY))
1748 if (VM_FF_IS_PENDING_EXCEPT(pVM, VM_FF_PDM_QUEUES, VM_FF_PGM_NO_MEMORY))
1749 PDMR3QueueFlushAll(pVM);
1754 if (VM_FF_IS_PENDING_EXCEPT(pVM, VM_FF_PDM_DMA, VM_FF_PGM_NO_MEMORY))
1755 PDMR3DmaRun(pVM);
1760 if (VM_FF_IS_PENDING(pVM, VM_FF_EMT_RENDEZVOUS))
1762 rc2 = VMMR3EmtRendezvousFF(pVM, pVCpu);
1780 if (VM_FF_IS_PENDING_EXCEPT(pVM, VM_FF_REQUEST, VM_FF_PGM_NO_MEMORY))
1782 rc2 = VMR3ReqProcessU(pVM->pUVM, VMCPUID_ANY, false /*fPriorityOnly*/);
1805 if (VM_FF_IS_PENDING_EXCEPT(pVM, VM_FF_REM_HANDLER_NOTIFY, VM_FF_PGM_NO_MEMORY))
1808 if ( pVM->cCpus == 1
1809 || ( !PGMIsLockOwner(pVM)
1810 && !IOMIsLockWriteOwner(pVM))
1813 EMRemLock(pVM);
1814 REMR3ReplayHandlerNotifications(pVM);
1815 EMRemUnlock(pVM);
1828 if ( !VM_FF_IS_PENDING(pVM, VM_FF_PGM_NO_MEMORY)
1836 rc2 = VMR3ReqProcessU(pVM->pUVM, pVCpu->idCpu, false /*fPriorityOnly*/);
1880 if ( VM_FF_IS_PENDING(pVM, VM_FF_HIGH_PRIORITY_PRE_MASK)
1887 && !VM_FF_IS_PENDING(pVM, VM_FF_PGM_NO_MEMORY))
1888 TMR3TimerQueuesDo(pVM);
1903 && !VM_FF_IS_PENDING(pVM, VM_FF_PGM_NO_MEMORY))
1918 if ( !VM_FF_IS_PENDING(pVM, VM_FF_PGM_NO_MEMORY)
1923 && PATMAreInterruptsEnabled(pVM)
1934 rc2 = TRPMR3InjectEvent(pVM, pVCpu, TRPM_HARDWARE_INT);
1935 if (pVM->em.s.fIemExecutesAll && (rc2 == VINF_EM_RESCHEDULE_REM || rc2 == VINF_EM_RESCHEDULE_HM || rc2 == VINF_EM_RESCHEDULE_RAW))
1946 else if (REMR3QueryPendingInterrupt(pVM, pVCpu) != REM_NO_PENDING_IRQ)
1948 Log2(("REMR3QueryPendingInterrupt -> %#x\n", REMR3QueryPendingInterrupt(pVM, pVCpu)));
1958 if (VM_FF_IS_PENDING_EXCEPT(pVM, VM_FF_PGM_NEED_HANDY_PAGES, VM_FF_PGM_NO_MEMORY))
1960 rc2 = PGMR3PhysAllocateHandyPages(pVM);
1967 if (VM_FF_IS_PENDING_EXCEPT(pVM, VM_FF_DBGF, VM_FF_PGM_NO_MEMORY))
1969 rc2 = DBGFR3VMMForcedAction(pVM);
1977 && VM_FF_IS_PENDING(pVM, VM_FF_EMT_RENDEZVOUS))
1979 rc2 = VMMR3EmtRendezvousFF(pVM, pVCpu);
1997 && VM_FF_IS_PENDING(pVM, VM_FF_CHECK_VM_STATE))
1999 VMSTATE enmState = VMR3GetState(pVM);
2024 if (VM_FF_IS_PENDING(pVM, VM_FF_PGM_NO_MEMORY))
2026 rc2 = PGMR3PhysAllocateHandyPages(pVM);
2035 if (VM_FF_IS_PENDING(pVM, VM_FF_TM_VIRTUAL_SYNC))
2036 TMR3VirtualSyncFF(pVM, pVCpu);
2042 if (VM_FF_IS_PENDING(pVM, VM_FF_DEBUG_SUSPEND))
2044 VM_FF_CLEAR(pVM, VM_FF_DEBUG_SUSPEND);
2067 * @param pVM Pointer to the VM.
2070 bool emR3IsExecutionAllowed(PVM pVM, PVMCPU pVCpu)
2074 if ( pVM->uCpuExecutionCap != 100
2087 Log2(("emR3IsExecutionAllowed: start=%RX64 startexec=%RX64 exec=%RX64 (cap=%x)\n", pVCpu->em.s.u64TimeSliceStart, pVCpu->em.s.u64TimeSliceStartExec, pVCpu->em.s.u64TimeSliceExec, (EM_TIME_SLICE * pVM->uCpuExecutionCap) / 100));
2088 if (pVCpu->em.s.u64TimeSliceExec >= (EM_TIME_SLICE * pVM->uCpuExecutionCap) / 100)
2109 * @param pVM Pointer to the VM.
2112 VMMR3_INT_DECL(int) EMR3ExecuteVM(PVM pVM, PVMCPU pVCpu)
2114 Log(("EMR3ExecuteVM: pVM=%p enmVMState=%d (%s) enmState=%d (%s) enmPrevState=%d (%s) fForceRAW=%RTbool\n",
2115 pVM,
2116 pVM->enmVMState, VMR3GetStateName(pVM->enmVMState),
2120 VM_ASSERT_EMT(pVM);
2132 TMR3NotifyResume(pVM, pVCpu);
2149 pVCpu->em.s.enmState = emR3Reschedule(pVM, pVCpu, pVCpu->em.s.pCtx);
2168 && ( VM_FF_IS_PENDING(pVM, VM_FF_ALL_REM_MASK)
2171 rc = emR3ForcedActions(pVM, pVCpu, rc);
2199 Assert(!pVM->em.s.fIemExecutesAll || pVCpu->em.s.enmState != EMSTATE_IEM);
2208 Assert(!pVM->em.s.fIemExecutesAll || pVCpu->em.s.enmState != EMSTATE_IEM);
2218 Assert(!pVM->em.s.fIemExecutesAll || pVCpu->em.s.enmState != EMSTATE_IEM);
2219 if (HMIsEnabled(pVM))
2236 Assert(!pVM->em.s.fIemExecutesAll || pVCpu->em.s.enmState != EMSTATE_IEM);
2260 EMSTATE enmState = emR3Reschedule(pVM, pVCpu, pVCpu->em.s.pCtx);
2304 EMSTATE enmState = emR3Reschedule(pVM, pVCpu, pVCpu->em.s.pCtx);
2324 TMR3NotifySuspend(pVM, pVCpu);
2334 if (pVM->enmVMState < VMSTATE_DESTROYING) /* ugly */
2335 TMR3NotifySuspend(pVM, pVCpu);
2348 TMR3NotifySuspend(pVM, pVCpu);
2351 rc = VMSetRuntimeError(pVM, VMSETRTERR_FLAGS_SUSPEND, "HostMemoryLow",
2407 if (!pVM->em.s.fGuruOnTripleFault)
2410 Assert(pVM->cCpus == 1);
2411 REMR3Reset(pVM);
2412 PGMR3ResetCpu(pVM, pVCpu);
2414 CPUMR3ResetCpu(pVM, pVCpu);
2417 pVCpu->em.s.enmState = emR3Reschedule(pVM, pVCpu, pVCpu->em.s.pCtx);
2485 rc = emR3RawExecute(pVM, pVCpu, &fFFDone);
2496 rc = emR3HmExecute(pVM, pVCpu, &fFFDone);
2503 rc = emR3RemExecute(pVM, pVCpu, &fFFDone);
2514 rc = VBOXSTRICTRC_TODO(EMR3HmSingleInstruction(pVM, pVCpu, EM_ONE_INS_FLAGS_RIP_CHANGE));
2521 if (pVM->em.s.fIemExecutesAll)
2538 rc = VBOXSTRICTRC_TODO(emR3ExecuteIemThenRem(pVM, pVCpu, &fFFDone));
2565 rc = VMR3WaitHalted(pVM, pVCpu, false /*fIgnoreInterrupts*/);
2576 rc = VMR3WaitHalted(pVM, pVCpu, !(CPUMGetGuestEFlags(pVCpu) & X86_EFL_IF));
2593 TMR3NotifySuspend(pVM, pVCpu);
2605 TMR3NotifySuspend(pVM, pVCpu);
2606 rc = VBOXSTRICTRC_TODO(emR3Debug(pVM, pVCpu, rc));
2607 TMR3NotifyResume(pVM, pVCpu);
2616 TMR3NotifySuspend(pVM, pVCpu);
2619 rc = VBOXSTRICTRC_TODO(emR3Debug(pVM, pVCpu, rc));
2629 VMMR3FatalDump(pVM, pVCpu, rc);
2636 TMR3NotifyResume(pVM, pVCpu);
2645 TMR3NotifySuspend(pVM, pVCpu);
2646 VMMR3FatalDump(pVM, pVCpu, rc);
2647 emR3Debug(pVM, pVCpu, rc);
2661 TMR3NotifySuspend(pVM, pVCpu);
2674 TMR3NotifySuspend(pVM, pVCpu);
2675 VMMR3FatalDump(pVM, pVCpu, rc);
2676 emR3Debug(pVM, pVCpu, rc);
2689 * @param pVM Pointer to the VM.
2691 VMMR3_INT_DECL(int) EMR3NotifySuspend(PVM pVM)
2693 PVMCPU pVCpu = VMMGetCpu(pVM);
2695 TMR3NotifySuspend(pVM, pVCpu); /* Stop the virtual time. */
2704 * @param pVM Pointer to the VM.
2706 VMMR3_INT_DECL(int) EMR3NotifyResume(PVM pVM)
2708 PVMCPU pVCpu = VMMGetCpu(pVM);
2711 TMR3NotifyResume(pVM, pVCpu); /* Resume the virtual time. */