VMMR0.cpp revision a21e8010cb45d12eef81d39c315728619caf4273
5b281ba489ca18f0380d7efc7a5108b606cce449vboxsync * VMM - Host Context Ring 0.
1c94c0a63ba68be1a7b2c640e70d7a06464e4fcavboxsync * Copyright (C) 2006-2007 Sun Microsystems, Inc.
29bdc01040c07a3dd482a94a2cb8f0a90f8587a7vboxsync * This file is part of VirtualBox Open Source Edition (OSE), as
29bdc01040c07a3dd482a94a2cb8f0a90f8587a7vboxsync * available from http://www.virtualbox.org. This file is free software;
29bdc01040c07a3dd482a94a2cb8f0a90f8587a7vboxsync * you can redistribute it and/or modify it under the terms of the GNU
a16eb14ad7a4b5ef91ddc22d3e8e92d930f736fcvboxsync * General Public License (GPL) as published by the Free Software
a16eb14ad7a4b5ef91ddc22d3e8e92d930f736fcvboxsync * Foundation, in version 2 as it comes in the "COPYING" file of the
a16eb14ad7a4b5ef91ddc22d3e8e92d930f736fcvboxsync * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
a16eb14ad7a4b5ef91ddc22d3e8e92d930f736fcvboxsync * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
a16eb14ad7a4b5ef91ddc22d3e8e92d930f736fcvboxsync * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
a16eb14ad7a4b5ef91ddc22d3e8e92d930f736fcvboxsync * Clara, CA 95054 USA or visit http://www.sun.com if you need
a16eb14ad7a4b5ef91ddc22d3e8e92d930f736fcvboxsync * additional information or have any questions.
a16eb14ad7a4b5ef91ddc22d3e8e92d930f736fcvboxsync/*******************************************************************************
a16eb14ad7a4b5ef91ddc22d3e8e92d930f736fcvboxsync* Header Files *
a16eb14ad7a4b5ef91ddc22d3e8e92d930f736fcvboxsync*******************************************************************************/
29bdc01040c07a3dd482a94a2cb8f0a90f8587a7vboxsync#if defined(_MSC_VER) && defined(RT_ARCH_AMD64) /** @todo check this with with VC7! */
29bdc01040c07a3dd482a94a2cb8f0a90f8587a7vboxsync/*******************************************************************************
29bdc01040c07a3dd482a94a2cb8f0a90f8587a7vboxsync* Internal Functions *
29bdc01040c07a3dd482a94a2cb8f0a90f8587a7vboxsync*******************************************************************************/
29bdc01040c07a3dd482a94a2cb8f0a90f8587a7vboxsync/*******************************************************************************
29bdc01040c07a3dd482a94a2cb8f0a90f8587a7vboxsync* Global Variables *
29bdc01040c07a3dd482a94a2cb8f0a90f8587a7vboxsync*******************************************************************************/
29bdc01040c07a3dd482a94a2cb8f0a90f8587a7vboxsync/** Pointer to the internal networking service instance. */
29bdc01040c07a3dd482a94a2cb8f0a90f8587a7vboxsync * Initialize the module.
29bdc01040c07a3dd482a94a2cb8f0a90f8587a7vboxsync * This is called when we're first loaded.
29bdc01040c07a3dd482a94a2cb8f0a90f8587a7vboxsync * @returns 0 on success.
29bdc01040c07a3dd482a94a2cb8f0a90f8587a7vboxsync * @returns VBox status on failure.
29bdc01040c07a3dd482a94a2cb8f0a90f8587a7vboxsync * Initialize the GVMM, GMM, HWACCM, PGM (Darwin) and INTNET.
29bdc01040c07a3dd482a94a2cb8f0a90f8587a7vboxsync LogFlow(("ModuleInit: g_pIntNet=%p\n", g_pIntNet));
29bdc01040c07a3dd482a94a2cb8f0a90f8587a7vboxsync LogFlow(("ModuleInit: g_pIntNet=%p should be NULL now...\n", g_pIntNet));
29bdc01040c07a3dd482a94a2cb8f0a90f8587a7vboxsync LogFlow(("ModuleInit: returns success. g_pIntNet=%p\n", g_pIntNet));
29bdc01040c07a3dd482a94a2cb8f0a90f8587a7vboxsync /* bail out */
if (g_pIntNet)
#ifdef VBOX_WITH_2X_4GB_ADDR_SPACE
HWACCMR0Term();
GMMR0Term();
GVMMR0Term();
return VERR_VERSION_MISMATCH;
return VERR_INVALID_PARAMETER;
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;
return rc;
#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 VMMCALLHOST_PDM_LOCK:
case VMMCALLHOST_PGM_LOCK:
#ifndef VBOX_WITH_NEW_PHYS_CODE
case VMMCALLHOST_VM_SET_ERROR:
case VINF_PGM_CHANGE_MODE:
case VINF_EM_PENDING_REQUEST:
switch (enmOperation)
return VERR_NOT_SUPPORTED;
* The return code is stored in pVM->vmm.s.iLastGZRc.
switch (enmOperation)
case VMMR0_DO_RAW_RUN:
#ifdef VBOX_WITH_STATISTICS
case VMMR0_DO_HWACC_RUN:
int rc;
if (!HWACCMR0SuspendPending())
rc = vmmR0CallHostSetJmp(&pVM->vmm.s.CallHostR0JmpBuf, 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, VMMR0OPERATION enmOperation, PSUPVMMR0REQHDR pReqHdr, uint64_t u64Arg, PSUPDRVSESSION pSession)
if (pVM)
return VERR_INVALID_POINTER;
return VERR_INVALID_POINTER;
switch (enmOperation)
case VMMR0_DO_GVMM_CREATE_VM:
return VERR_INVALID_PARAMETER;
case VMMR0_DO_GVMM_DESTROY_VM:
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_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:
return VERR_NOT_SUPPORTED;
return rc;
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))
return VERR_INVALID_PARAMETER;
if (!g_pIntNet)
return VERR_NOT_SUPPORTED;
if (u64Arg || !pReqHdr || !vmmR0IsValidSession(pVM, ((PINTNETIFGETRING3BUFFERREQ)pReqHdr)->pSession, pSession))
return VERR_INVALID_PARAMETER;
if (!g_pIntNet)
return VERR_NOT_SUPPORTED;
if (u64Arg || !pReqHdr || !vmmR0IsValidSession(pVM, ((PINTNETIFSETPROMISCUOUSMODEREQ)pReqHdr)->pSession, pSession))
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))
return VERR_INVALID_PARAMETER;
if (!g_pIntNet)
return VERR_NOT_SUPPORTED;
if (u64Arg || !pReqHdr || !vmmR0IsValidSession(pVM, ((PINTNETIFSETACTIVEREQ)pReqHdr)->pSession, pSession))
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))
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))
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_NOT_SUPPORTED;
typedef struct VMMR0ENTRYEXARGS
VMMR0DECL(int) VMMR0EntryEx(PVM pVM, VMMR0OPERATION enmOperation, PSUPVMMR0REQHDR pReq, uint64_t u64Arg, PSUPDRVSESSION pSession)
switch (enmOperation)
case VMMR0_DO_GMM_FREE_PAGES:
case VMMR0_DO_GMM_SEED_CHUNK:
case VMMR0_DO_VMMR0_INIT:
case VMMR0_DO_VMMR0_TERM:
#ifdef DEBUG
#ifdef DEBUG
#ifdef RT_ARCH_X86
#ifdef DEBUG
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