PGMSharedPage.cpp revision 9d7fdfd90ef8d681a2d2c339339e8dc0b1fc5bd3
/* $Id$ */
/** @file
* PGM - Page Manager and Monitor, Shared page handling
*/
/*
* Copyright (C) 2006-2010 Oracle Corporation
*
* 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 (GPL) 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.
*/
/*******************************************************************************
* Header Files *
*******************************************************************************/
#define LOG_GROUP LOG_GROUP_PGM
#include "PGMInternal.h"
#include "PGMInline.h"
#ifdef VBOX_WITH_PAGE_SHARING
/**
* Rendezvous callback that will be called once.
*
* @returns VBox strict status code.
* @param pVM VM handle.
* @param pVCpu The VMCPU handle for the calling EMT.
* @param pvUser PGMMREGISTERSHAREDMODULEREQ
*/
static DECLCALLBACK(VBOXSTRICTRC) pgmR3SharedModuleRegRendezvous(PVM pVM, PVMCPU pVCpu, void *pvUser)
{
}
/**
* Shared module registration helper (called on the way out).
*
* @param pVM The VM handle.
* @param pReq Registration request info
*/
static DECLCALLBACK(void) pgmR3SharedModuleRegisterHelper(PVM pVM, PGMMREGISTERSHAREDMODULEREQ pReq)
{
int rc;
Assert(rc == VINF_SUCCESS || rc == VINF_PGM_SHARED_MODULE_COLLISION || rc == VINF_PGM_SHARED_MODULE_ALREADY_REGISTERED);
{
unsigned cFlushedPages = 0;
/** todo count copy-on-write actions in the trap handler so we don't have to check everything all the time! */
/* Count the number of shared pages that were changed (copy-on-write). */
{
while (cbRegion)
{
if ( rc == VINF_SUCCESS
&& !(fFlags & X86_PTE_RW))
{
if ( pPage
&& !PGM_PAGE_IS_SHARED(pPage))
{
}
}
}
}
if (cFlushedPages > 32)
}
/* Full (re)check needed? */
if (rc == VINF_SUCCESS)
{
/* We must stall other VCPUs as we'd otherwise have to send IPI flush commands for every single change we make. */
rc = VMMR3EmtRendezvous(pVM, VMMEMTRENDEZVOUS_FLAGS_TYPE_ONCE, pgmR3SharedModuleRegRendezvous, pReq);
}
return;
}
#endif
/**
* Registers a new shared module for the VM
*
* @returns VBox status code.
* @param pVM VM handle
* @param pszModuleName Module name
* @param pszVersion Module version
* @param GCBaseAddr Module base address
* @param cbModule Module size
* @param cRegions Number of shared region descriptors
* @param pRegions Shared region(s)
*/
VMMR3DECL(int) PGMR3SharedModuleRegister(PVM pVM, char *pszModuleName, char *pszVersion, RTGCPTR GCBaseAddr, uint32_t cbModule,
{
#ifdef VBOX_WITH_PAGE_SHARING
/* Sanity check. */
pReq = (PGMMREGISTERSHAREDMODULEREQ)RTMemAllocZ(RT_OFFSETOF(GMMREGISTERSHAREDMODULEREQ, aRegions[cRegions]));
for (unsigned i = 0; i < cRegions; i++)
{
return VERR_BUFFER_OVERFLOW;
}
/* Queue the actual registration as we are under the IOM lock right now. Perform this operation on the way out. */
return VMR3ReqCallNoWait(pVM, VMMGetCpuId(pVM), (PFNRT)pgmR3SharedModuleRegisterHelper, 2, pVM, pReq);
#else
return VERR_NOT_IMPLEMENTED;
#endif
}
#ifdef VBOX_WITH_PAGE_SHARING
/**
* Shared module unregistration helper (called on the way out).
*
* @param pVM The VM handle.
* @param pReq Unregistration request info
*/
static DECLCALLBACK(void) pgmR3SharedModuleUnregisterHelper(PVM pVM, PGMMREGISTERSHAREDMODULEREQ pReq)
{
int rc;
return;
}
#endif
/**
* Unregisters a shared module for the VM
*
* @returns VBox status code.
* @param pVM VM handle
* @param pszModuleName Module name
* @param pszVersion Module version
* @param GCBaseAddr Module base address
* @param cbModule Module size
*/
VMMR3DECL(int) PGMR3SharedModuleUnregister(PVM pVM, char *pszModuleName, char *pszVersion, RTGCPTR GCBaseAddr, uint32_t cbModule)
{
#ifdef VBOX_WITH_PAGE_SHARING
{
return VERR_BUFFER_OVERFLOW;
}
/* Queue the actual registration as we are under the IOM lock right now. Perform this operation on the way out. */
return VMR3ReqCallNoWait(pVM, VMMGetCpuId(pVM), (PFNRT)pgmR3SharedModuleUnregisterHelper, 2, pVM, pReq);
#else
return VERR_NOT_IMPLEMENTED;
#endif
}
/**
* Checks regsitered modules for shared pages
*
* @returns VBox status code.
* @param pVM VM handle
*/
{
#ifdef VBOX_WITH_PAGE_SHARING
return GMMR3CheckSharedModules(pVM);
#else
return VERR_NOT_IMPLEMENTED;
#endif
}