VMMR0.cpp revision a63dfea04c51d4be12ffd06c25945571459e34d1
5383c976362d5b18656cf7b9248b2063a764a203vboxsync * VMM - Host Context Ring 0.
5383c976362d5b18656cf7b9248b2063a764a203vboxsync * Copyright (C) 2006-2007 Sun Microsystems, Inc.
5383c976362d5b18656cf7b9248b2063a764a203vboxsync * This file is part of VirtualBox Open Source Edition (OSE), as
5383c976362d5b18656cf7b9248b2063a764a203vboxsync * available from http://www.virtualbox.org. This file is free software;
5383c976362d5b18656cf7b9248b2063a764a203vboxsync * you can redistribute it and/or modify it under the terms of the GNU
5383c976362d5b18656cf7b9248b2063a764a203vboxsync * General Public License (GPL) as published by the Free Software
5383c976362d5b18656cf7b9248b2063a764a203vboxsync * Foundation, in version 2 as it comes in the "COPYING" file of the
5383c976362d5b18656cf7b9248b2063a764a203vboxsync * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
5383c976362d5b18656cf7b9248b2063a764a203vboxsync * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
5383c976362d5b18656cf7b9248b2063a764a203vboxsync * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
5383c976362d5b18656cf7b9248b2063a764a203vboxsync * Clara, CA 95054 USA or visit http://www.sun.com if you need
5383c976362d5b18656cf7b9248b2063a764a203vboxsync * additional information or have any questions.
5383c976362d5b18656cf7b9248b2063a764a203vboxsync/*******************************************************************************
5383c976362d5b18656cf7b9248b2063a764a203vboxsync* Header Files *
5383c976362d5b18656cf7b9248b2063a764a203vboxsync*******************************************************************************/
5383c976362d5b18656cf7b9248b2063a764a203vboxsync#if defined(_MSC_VER) && defined(RT_ARCH_AMD64) /** @todo check this with with VC7! */
5383c976362d5b18656cf7b9248b2063a764a203vboxsync/*******************************************************************************
#ifdef VBOX_WITH_2X_4GB_ADDR_SPACE
return VINF_SUCCESS;
#ifdef VBOX_WITH_2X_4GB_ADDR_SPACE
HWACCMR0Term();
GMMR0Term();
GVMMR0Term();
return rc;
if (g_pIntNet)
#ifdef VBOX_WITH_2X_4GB_ADDR_SPACE
HWACCMR0Term();
GMMR0Term();
GVMMR0Term();
return VERR_VERSION_MISMATCH;
return VERR_INVALID_PARAMETER;
#ifdef LOG_ENABLED
if (pR0Logger)
LogCom(("vmmR0InitVM: offScratch=%d fFlags=%#x fDestFlags=%#x\n", pR0Logger->Logger.offScratch, pR0Logger->Logger.fFlags, pR0Logger->Logger.fDestFlags));
LogCom(("vmmR0InitVM: returned succesfully from direct logger call (2). offScratch=%d\n", pR0Logger->Logger.offScratch));
#ifdef VBOX_WITH_2X_4GB_ADDR_SPACE
return rc;
return rc;
#ifdef VBOX_WITH_2X_4GB_ADDR_SPACE
return VINF_SUCCESS;
#ifdef VBOX_WITH_STATISTICS
switch (rc)
case VINF_SUCCESS:
case VINF_EM_RAW_INTERRUPT:
case VINF_EM_RAW_GUEST_TRAP:
case VINF_EM_RAW_RING_SWITCH:
case VINF_EM_RAW_IRET_TRAP:
case VINF_IOM_HC_IOPORT_READ:
case VINF_IOM_HC_IOPORT_WRITE:
case VINF_IOM_HC_MMIO_READ:
case VINF_IOM_HC_MMIO_WRITE:
case VINF_PATCH_EMULATE_INSTR:
case VINF_CSAM_PENDING_ACTION:
case VINF_PGM_SYNC_CR3:
case VINF_PATM_PATCH_INT3:
case VINF_PATM_PATCH_TRAP_PF:
case VINF_PATM_PATCH_TRAP_GP:
case VINF_EM_RESCHEDULE_REM:
case VINF_EM_RAW_TO_R3:
case VINF_VMM_CALL_HOST:
case VMMCALLRING3_PDM_LOCK:
case VMMCALLRING3_PGM_LOCK:
case VINF_PGM_CHANGE_MODE:
case VINF_EM_PENDING_REQUEST:
return VERR_NOT_SUPPORTED;
* The return code is stored in pVM->vmm.s.iLastGZRc.
switch (enmOperation)
case VMMR0_DO_RAW_RUN:
int rc;
bool fVTxDisabled;
#ifdef VBOX_WITH_STATISTICS
case VMMR0_DO_HWACC_RUN:
int rc;
#ifdef LOG_ENABLED
if ( pR0Logger
if (!HWACCMR0SuspendPending())
rc = vmmR0CallRing3SetJmp(&pVCpu->vmm.s.CallRing3JmpBufR0, HWACCMR0RunGuestCode, pVM, pVCpu); /* this may resume code. */
#ifdef VBOX_WITH_STATISTICS
case VMMR0_DO_NOP:
DECLINLINE(bool) vmmR0IsValidSession(PVM pVM, PSUPDRVSESSION pClaimedSession, PSUPDRVSESSION pSession)
if (!pSession)
if (pVM)
static int vmmR0EntryExWorker(PVM pVM, VMCPUID idCpu, VMMR0OPERATION enmOperation, PSUPVMMR0REQHDR pReqHdr, uint64_t u64Arg, PSUPDRVSESSION pSession)
if (pVM)
return VERR_INVALID_POINTER;
return VERR_INVALID_POINTER;
return VERR_INVALID_PARAMETER;
return VERR_INVALID_PARAMETER;
switch (enmOperation)
case VMMR0_DO_GVMM_CREATE_VM:
return VERR_INVALID_PARAMETER;
case VMMR0_DO_GVMM_DESTROY_VM:
return VERR_INVALID_PARAMETER;
if (!pVM)
return VERR_INVALID_PARAMETER;
case VMMR0_DO_GVMM_SCHED_HALT:
if (pReqHdr)
return VERR_INVALID_PARAMETER;
return VERR_INVALID_PARAMETER;
case VMMR0_DO_GVMM_SCHED_POKE:
return VERR_INVALID_PARAMETER;
if (u64Arg)
return VERR_INVALID_PARAMETER;
case VMMR0_DO_GVMM_SCHED_POLL:
return VERR_INVALID_PARAMETER;
if (u64Arg)
return VERR_INVALID_PARAMETER;
if (u64Arg)
return VERR_INVALID_PARAMETER;
case VMMR0_DO_VMMR0_INIT:
case VMMR0_DO_VMMR0_TERM:
case VMMR0_DO_HWACC_ENABLE:
case VMMR0_DO_HWACC_SETUP_VM:
return rc;
case VMMR0_DO_CALL_HYPERVISOR:
int rc;
bool fVTxDisabled;
return VERR_NOT_SUPPORTED;
return VERR_PGM_NO_CR3_SHADOW_ROOT;
return rc;
return rc;
return VERR_INVALID_CPU_ID;
if (u64Arg)
return VERR_INVALID_PARAMETER;
if (u64Arg)
return VERR_INVALID_PARAMETER;
if (u64Arg)
return VERR_INVALID_PARAMETER;
case VMMR0_DO_GMM_FREE_PAGES:
if (u64Arg)
return VERR_INVALID_PARAMETER;
if (u64Arg)
return VERR_INVALID_PARAMETER;
if (pReqHdr)
return VERR_INVALID_PARAMETER;
if (u64Arg)
return VERR_INVALID_PARAMETER;
case VMMR0_DO_GMM_SEED_CHUNK:
if (pReqHdr)
return VERR_INVALID_PARAMETER;
case VMMR0_DO_GCFGM_SET_VALUE:
return VERR_INVALID_PARAMETER;
return VERR_INVALID_PARAMETER;
int rc;
return rc;
case VMMR0_DO_INTNET_OPEN:
return VERR_INVALID_PARAMETER;
if (!g_pIntNet)
return VERR_NOT_SUPPORTED;
case VMMR0_DO_INTNET_IF_CLOSE:
if (u64Arg || !pReqHdr || !vmmR0IsValidSession(pVM, ((PINTNETIFCLOSEREQ)pReqHdr)->pSession, pSession) || idCpu != NIL_VMCPUID)
return VERR_INVALID_PARAMETER;
if (!g_pIntNet)
return VERR_NOT_SUPPORTED;
if (u64Arg || !pReqHdr || !vmmR0IsValidSession(pVM, ((PINTNETIFGETRING3BUFFERREQ)pReqHdr)->pSession, pSession) || idCpu != NIL_VMCPUID)
return VERR_INVALID_PARAMETER;
if (!g_pIntNet)
return VERR_NOT_SUPPORTED;
if (u64Arg || !pReqHdr || !vmmR0IsValidSession(pVM, ((PINTNETIFSETPROMISCUOUSMODEREQ)pReqHdr)->pSession, pSession) || idCpu != NIL_VMCPUID)
return VERR_INVALID_PARAMETER;
if (!g_pIntNet)
return VERR_NOT_SUPPORTED;
return INTNETR0IfSetPromiscuousModeReq(g_pIntNet, pSession, (PINTNETIFSETPROMISCUOUSMODEREQ)pReqHdr);
if (u64Arg || !pReqHdr || !vmmR0IsValidSession(pVM, ((PINTNETIFSETMACADDRESSREQ)pReqHdr)->pSession, pSession) || idCpu != NIL_VMCPUID)
return VERR_INVALID_PARAMETER;
if (!g_pIntNet)
return VERR_NOT_SUPPORTED;
if (u64Arg || !pReqHdr || !vmmR0IsValidSession(pVM, ((PINTNETIFSETACTIVEREQ)pReqHdr)->pSession, pSession) || idCpu != NIL_VMCPUID)
return VERR_INVALID_PARAMETER;
if (!g_pIntNet)
return VERR_NOT_SUPPORTED;
case VMMR0_DO_INTNET_IF_SEND:
if (u64Arg || !pReqHdr || !vmmR0IsValidSession(pVM, ((PINTNETIFSENDREQ)pReqHdr)->pSession, pSession) || idCpu != NIL_VMCPUID)
return VERR_INVALID_PARAMETER;
if (!g_pIntNet)
return VERR_NOT_SUPPORTED;
case VMMR0_DO_INTNET_IF_WAIT:
if (u64Arg || !pReqHdr || !vmmR0IsValidSession(pVM, ((PINTNETIFWAITREQ)pReqHdr)->pSession, pSession) || idCpu != NIL_VMCPUID)
return VERR_INVALID_PARAMETER;
if (!g_pIntNet)
return VERR_NOT_SUPPORTED;
case VMMR0_DO_NOP:
case VMMR0_DO_SLOW_NOP:
return VINF_SUCCESS;
case VMMR0_DO_TESTS:
return VINF_SUCCESS;
#if HC_ARCH_BITS == 32 && defined(VBOX_WITH_64_BITS_GUESTS) && !defined(VBOX_WITH_HYBRID_32BIT_KERNEL)
return VERR_INVALID_CPU_ID;
return VERR_NOT_SUPPORTED;
typedef struct VMMR0ENTRYEXARGS
VMMR0DECL(int) VMMR0EntryEx(PVM pVM, VMCPUID idCpu, VMMR0OPERATION enmOperation, PSUPVMMR0REQHDR pReq, uint64_t u64Arg, PSUPDRVSESSION pSession)
switch (enmOperation)
case VMMR0_DO_GMM_FREE_PAGES:
case VMMR0_DO_VMMR0_INIT:
case VMMR0_DO_VMMR0_TERM:
#ifdef LOG_ENABLED
# ifdef DEBUG
# ifdef DEBUG
# ifdef RT_ARCH_X86
# ifdef DEBUG
#ifdef LOG_ENABLED
#ifdef LOG_ENABLED
if (pVM)
#ifdef RT_ARCH_X86
#ifdef RT_OS_LINUX
DECLEXPORT(void) RTCALL AssertMsg1(const char *pszExpr, unsigned uLine, const char *pszFile, const char *pszFunction)
if (pVM)
#ifdef RT_OS_DARWIN
return cbChars;
if (pLog)
if (pVM)
#ifdef RT_OS_DARWIN