CSAMAll.cpp revision 5aefacb29c648cdea4211b783e04d52223ddb257
/* $Id$ */
/** @file
* CSAM - Guest OS Code Scanning and Analysis Manager - Any Context
*/
/*
* Copyright (C) 2006-2007 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_CSAM
#include "CSAMInternal.h"
#include <VBox/disopcode.h>
/**
* Check if this page needs to be analysed by CSAM
*
* @returns VBox status code
* @param pVM The VM to operate on.
* @param pvFault Fault address
*/
{
if(!CSAMIsEnabled(pVM))
return VINF_SUCCESS;
{
// Already checked!
return VINF_SUCCESS;
}
return VINF_CSAM_PENDING_ACTION;
}
/**
* Check if this page was previously scanned by CSAM
*
* @returns true -> scanned, false -> not scanned
* @param pVM The VM to operate on.
* @param pPage GC page address
*/
{
return pVM->csam.s.CTXSUFF(pPDBitmap)[pgdir] && ASMBitTest((void *)pVM->csam.s.CTXSUFF(pPDBitmap)[pgdir], bit);
}
/**
*
* @note: we always mark it as scanned, even if we haven't completely done so
*
* @returns VBox status code.
* @param pVM The VM to operate on.
* @param pPage GC page address (not necessarily aligned)
* @param fScanned Mark as scanned or not scanned
*
*/
{
#ifdef LOG_ENABLED
#endif
if(!CSAMIsEnabled(pVM))
return VINF_SUCCESS;
{
int rc = MMHyperAlloc(pVM, CSAM_PAGE_BITMAP_SIZE, 0, MM_TAG_CSAM, (void **)&pVM->csam.s.CTXSUFF(pPDBitmap)[pgdir]);
if (RT_FAILURE(rc))
{
return rc;
}
#ifdef IN_RC
pVM->csam.s.pPDHCBitmapGC[pgdir] = MMHyperRCToR3(pVM, (RCPTRTYPE(void*))pVM->csam.s.pPDBitmapGC[pgdir]);
{
return rc;
}
#else
{
return rc;
}
#endif
}
if(fScanned)
else
return VINF_SUCCESS;
}
/**
* Check if this page needs to be analysed by CSAM.
*
* This function should only be called for supervisor pages and
* only when CSAM is enabled. Leaving these selection criteria
* to the caller simplifies the interface (PTE passing).
*
* Note that the page has not yet been synced, so the TLB trick
* (which wasn't ever active anyway) cannot be applied.
*
* @returns true if the page should be marked not present because
* CSAM want need to scan it.
* @returns false if the page was already scanned.
* @param pVM The VM to operate on.
* @param GCPtr GC pointer of page
*/
{
if(!CSAMIsEnabled(pVM))
return false;
{
/* Already checked! */
return false;
}
return true;
}
/**
* Remember a possible code page for later inspection
*
* @returns VBox status code.
* @param pVM The VM to operate on.
* @param GCPtr GC pointer of page
*/
{
{
}
return;
}
/**
* Turn on code scanning
*
* @returns VBox status code.
* @param pVM The VM to operate on.
*/
{
pVM->fCSAMEnabled = true;
return VINF_SUCCESS;
}
/**
* Turn off code scanning
*
* @returns VBox status code.
* @param pVM The VM to operate on.
*/
{
pVM->fCSAMEnabled = false;
return VINF_SUCCESS;
}
/**
* Check if we've scanned this instruction before. If true, then we can emulate
* it instead of returning to ring 3.
*
* Using a simple array here as there are generally few mov crx instructions and
* tree lookup is likely to be more expensive. (as it would also have to be offset based)
*
* @returns boolean
* @param pVM The VM to operate on.
* @param GCPtr GC pointer of page table entry
*/
{
{
{
return true;
}
}
/* Record that we're about to process it in ring 3. */
return false;
}