VMMR0.cpp revision c6ab81d51d7adcb80328ce4310523bd3d9d0a879
/* $Id$ */
/** @file
* VMM - Host Context Ring 0.
*/
/*
* Copyright (C) 2006 InnoTek Systemberatung GmbH
*
* This file is part of VirtualBox Open Source Edition (OSE), as
* available from http://www.virtualbox.org. This file is free software;
* General Public License as published by the Free Software Foundation,
* in version 2 as it comes in the "COPYING" file of the VirtualBox OSE
* distribution. VirtualBox OSE is distributed in the hope that it will
* be useful, but WITHOUT ANY WARRANTY of any kind.
*
* If you received this file as part of a commercial VirtualBox
* distribution, then only the terms of your commercial VirtualBox
* license agreement apply instead of the previous paragraph.
*/
/*******************************************************************************
* Header Files *
*******************************************************************************/
#define LOG_GROUP LOG_GROUP_VMM
#include "VMMInternal.h"
# pragma intrinsic(_AddressOfReturnAddress)
#endif
/*******************************************************************************
* Internal Functions *
*******************************************************************************/
VMMR0DECL(int) ModuleInit(void);
VMMR0DECL(void) ModuleTerm(void);
#ifndef __AMD64__ /* causes crashes in Vista here; disabling for now */
#ifdef DEBUG
#define DEBUG_NO_RING0_ASSERTIONS
#ifdef DEBUG_NO_RING0_ASSERTIONS
static PVM g_pVMAssert = 0;
#endif
#endif
#endif
/*******************************************************************************
* Global Variables *
*******************************************************************************/
/** Pointer to the internal networking service instance. */
#endif
/**
* Initialize the module.
* This is called when we're first loaded.
*
* @returns 0 on success.
* @returns VBox status on failure.
*/
VMMR0DECL(int) ModuleInit(void)
{
if (VBOX_SUCCESS(rc))
{
return 0;
}
return rc;
#else
return 0;
#endif
}
/**
* Terminate the module.
* This is called when we're finally unloaded.
*/
VMMR0DECL(void) ModuleTerm(void)
{
LogFlow(("ModuleTerm:\n"));
if (g_pIntNet)
{
}
LogFlow(("ModuleTerm: returns\n"));
#endif
}
/**
* Initaties the R0 driver for a particular VM instance.
*
* @returns VBox status code.
*
* @param pVM The VM instance in question.
* @param uVersion The minimum module version required.
*/
{
/*
* Check if compatible version.
*/
if ( uVersion != VBOX_VERSION
return VERR_VERSION_MISMATCH;
return VERR_INVALID_PARAMETER;
/*
* Register the EMT R0 logger instance.
*/
if (pR0Logger)
{
#if 0 /* testing of the logger. */
LogCom(("VMMR0Init: offScratch=%d fFlags=%#x fDestFlags=%#x\n", pR0Logger->Logger.offScratch, pR0Logger->Logger.fFlags, pR0Logger->Logger.fDestFlags));
LogCom(("VMMR0Init: returned succesfully from direct logger call.\n"));
LogCom(("VMMR0Init: returned succesfully from direct flush call.\n"));
LogCom(("VMMR0Init: returned succesfully from direct logger call (2). offScratch=%d\n", pR0Logger->Logger.offScratch));
#endif
}
/*
* Init VMXM.
*/
/*
* Init CPUM.
*/
if (RT_FAILURE(rc))
return rc;
}
/**
* Terminates the R0 driver for a particular VM instance.
*
* @returns VBox status code.
*
* @param pVM The VM instance in question.
*/
{
/*
* Deregister the logger.
*/
return VINF_SUCCESS;
}
/**
* Calls the ring-3 host code.
*
* @returns VBox status code of the ring-3 call.
* @param pVM The VM handle.
* @param enmOperation The operation.
* @param uArg The argument to the operation.
*/
{
/** @todo profile this! */
if (rc == VINF_SUCCESS)
return rc;
}
#ifdef VBOX_WITH_STATISTICS
/**
* Record return code statistics
* @param pVM The VM handle.
* @param rc The status code.
*/
{
/*
* Collect statistics.
*/
switch (rc)
{
case VINF_SUCCESS:
break;
case VINF_EM_RAW_INTERRUPT:
break;
break;
case VINF_EM_RAW_GUEST_TRAP:
break;
case VINF_EM_RAW_RING_SWITCH:
break;
break;
break;
break;
case VINF_EM_RAW_IRET_TRAP:
break;
case VINF_IOM_HC_IOPORT_READ:
break;
case VINF_IOM_HC_IOPORT_WRITE:
break;
case VINF_IOM_HC_MMIO_READ:
break;
case VINF_IOM_HC_MMIO_WRITE:
break;
break;
break;
break;
break;
case VINF_PATCH_EMULATE_INSTR:
break;
break;
break;
break;
break;
break;
case VINF_CSAM_PENDING_ACTION:
break;
case VINF_PGM_SYNC_CR3:
break;
case VINF_PATM_PATCH_INT3:
break;
case VINF_PATM_PATCH_TRAP_PF:
break;
case VINF_PATM_PATCH_TRAP_GP:
break;
break;
break;
case VINF_EM_RESCHEDULE_REM:
break;
case VINF_EM_RAW_TO_R3:
break;
break;
break;
case VINF_VMM_CALL_HOST:
{
case VMMCALLHOST_PDM_LOCK:
break;
break;
break;
case VMMCALLHOST_PGM_LOCK:
break;
break;
break;
break;
case VMMCALLHOST_VM_SET_ERROR:
break;
break;
default:
break;
}
break;
break;
case VINF_PGM_CHANGE_MODE:
break;
break;
case VINF_EM_PENDING_REQUEST:
break;
default:
break;
}
}
#endif /* VBOX_WITH_STATISTICS */
/**
* The Ring 0 entry point, called by the support library (SUP).
*
* @returns VBox status code.
* @param pVM The VM to operate on.
* @param uOperation Which operation to execute. (VMMR0OPERATION)
* @param pvArg Argument to the operation.
*/
{
switch (uOperation)
{
/*
* Switch to GC.
* These calls return whatever the GC returns.
*/
case VMMR0_DO_RAW_RUN:
{
/* Safety precaution as VMX disables the switcher. */
return VERR_NOT_SUPPORTED;
register int rc;
#ifdef VBOX_WITH_STATISTICS
#endif
/*
* Check if there is an exit R0 action associated with the return code.
*/
switch (rc)
{
/*
* Default - no action, just return.
*/
default:
return rc;
/*
* We'll let TRPM change the stack frame so our return is different.
* Just keep in mind that after the call, things have changed!
*/
case VINF_EM_RAW_INTERRUPT:
{
#ifdef VBOX_WITHOUT_IDT_PATCHING
#else /* !VBOX_WITHOUT_IDT_PATCHING */
/*
* Don't trust the compiler to get this right.
* gcc -fomit-frame-pointer screws up big time here. This works fine in 64-bit
* mode too because we push the arguments on the stack in the IDT patch code.
*/
# if defined(__GNUC__)
# else
# error "huh?"
# endif
else
{
# if defined(DEBUG) || defined(LOG_ENABLED)
static bool s_fHaveWarned = false;
if (!s_fHaveWarned)
{
s_fHaveWarned = true;
//RTLogPrintf("VMMR0.r0: The compiler can't find the stack frame!\n"); -- @todo export me!
RTLogComPrintf("VMMR0.r0: The compiler can't find the stack frame!\n");
}
# endif
}
#endif /* !VBOX_WITHOUT_IDT_PATCHING */
return rc;
}
}
/* Won't get here! */
break;
}
/*
* Run guest code using the available hardware acceleration technology.
*/
case VMMR0_DO_HWACC_RUN:
{
int rc;
if (VBOX_SUCCESS(rc))
{
#ifdef DEBUG_NO_RING0_ASSERTIONS
g_pVMAssert = pVM;
#endif
rc = vmmR0CallHostSetJmp(&pVM->vmm.s.CallHostR0JmpBuf, HWACCMR0RunGuestCode, pVM); /* this may resume code. */
#ifdef DEBUG_NO_RING0_ASSERTIONS
g_pVMAssert = 0;
#endif
}
#ifdef VBOX_WITH_STATISTICS
#endif
/* No special action required for external interrupts, just return. */
return rc;
}
/*
* Initialize the R0 part of a VM instance.
*/
case VMMR0_DO_VMMR0_INIT:
{
return rc;
}
/*
* Terminate the R0 part of a VM instance.
*/
case VMMR0_DO_VMMR0_TERM:
{
return rc;
}
/*
* Setup the hardware accelerated raw-mode session.
*/
case VMMR0_DO_HWACC_SETUP_VM:
{
return rc;
}
/*
* Switch to GC to execute Hypervisor function.
*/
case VMMR0_DO_CALL_HYPERVISOR:
{
/* Safety precaution as VMX disables the switcher. */
return VERR_NOT_SUPPORTED;
return rc;
}
/*
* Services.
*/
case VMMR0_DO_INTNET_OPEN:
case VMMR0_DO_INTNET_IF_CLOSE:
case VMMR0_DO_INTNET_IF_SEND:
case VMMR0_DO_INTNET_IF_WAIT:
{
/*
* Validate arguments a bit first.
*/
return VERR_INVALID_POINTER;
return VERR_INVALID_POINTER;
return VERR_INVALID_POINTER;
return VERR_INVALID_POINTER;
if (!g_pIntNet)
return VERR_FILE_NOT_FOUND; ///@todo fix this status code!
/*
* Unpack the arguments and call the service.
*/
switch (uOperation)
{
case VMMR0_DO_INTNET_OPEN:
{
return INTNETR0Open(g_pIntNet, pVM->pSession, &pArgs->szNetwork[0], pArgs->cbSend, pArgs->cbRecv, pArgs->fRestrictAccess, &pArgs->hIf);
}
case VMMR0_DO_INTNET_IF_CLOSE:
{
}
{
}
{
}
case VMMR0_DO_INTNET_IF_SEND:
{
}
case VMMR0_DO_INTNET_IF_WAIT:
{
}
default:
return VERR_NOT_SUPPORTED;
}
}
#endif /* VBOX_WITH_INTERNAL_NETWORKING */
/*
* For profiling.
*/
case VMMR0_DO_NOP:
return VINF_SUCCESS;
/*
* For testing Ring-0 APIs invoked in this environment.
*/
case VMMR0_DO_TESTS:
/** @todo make new test */
return VINF_SUCCESS;
default:
/*
* We're returning VERR_NOT_SUPPORT here so we've got something else
* than -1 which the interrupt gate glue code might return.
*/
return VERR_NOT_SUPPORTED;
}
}
/**
* Internal R0 logger worker: Flush logger.
*
* @param pLogger The logger instance to flush.
* @remark This function must be exported!
*/
{
/*
* Convert the pLogger into a VM handle and 'call' back to Ring-3.
* (This is a bit paranoid code.)
*/
{
return;
}
{
return;
}
/*
* Check that the jump buffer is armed.
*/
#ifdef __X86__
#else
#endif
{
LogCom(("vmmR0LoggerFlush: Jump buffer isn't armed!\n"));
pLogger->offScratch = 0;
return;
}
}
void R0LogFlush()
{
}
#ifdef DEBUG_NO_RING0_ASSERTIONS
#define LOG_GROUP LOG_GROUP_EM
/**
* Check if we really want to hit a breakpoint.
* Can jump back to ring-3 when the longjmp is armed.
*/
{
if (g_pVMAssert)
{
if (rc == VINF_SUCCESS)
}
return false;
}
/** Runtime assert implementation for Native Win32 Ring-0. */
DECLEXPORT(void) RTCALL AssertMsg1(const char *pszExpr, unsigned uLine, const char *pszFile, const char *pszFunction)
{
Log(("\n!!R0-Assertion Failed!!\n"
"Expression: %s\n"
"Location : %s(%d) %s\n",
}
/**
* Callback for RTLogFormatV which writes to the com port.
* See PFNLOGOUTPUT() for details.
*/
{
return cbChars;
}
{
if (pLog)
{
R0LogFlush();
}
}
#endif