tstPageFusion.cpp revision 3516e08dce457c041b71a7075d65bf9ea367b2fd
/* $Id: VBoxServicePageSharing.cpp 62335 2010-06-03 14:40:59Z bird $ */
/** @file
* VBoxService - Guest page sharing testcase
*/
/*
* 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 *
*******************************************************************************/
#include <iprt/initterm.h>
#include <VBox/VBoxGuestLib.h>
#include <stdio.h>
/*******************************************************************************
* Global Variables *
*******************************************************************************/
#ifdef RT_OS_WINDOWS
#include <Windows.h>
#include <process.h> /* Needed for file version information. */
#include <tlhelp32.h>
#include <psapi.h>
#include <winternl.h>
#define SystemModuleInformation 11
typedef struct _RTL_PROCESS_MODULE_INFORMATION
{
typedef struct _RTL_PROCESS_MODULES
{
#define PAGE_STATE_INVALID 0
#define PAGE_STATE_SHARED 1
#define PAGE_STATE_READ_WRITE 2
#define PAGE_STATE_READ_ONLY 3
#define PAGE_STATE_NOT_PRESENT 4
/* Page counters. */
static unsigned cNotPresentPages = 0;
static unsigned cWritablePages = 0;
static unsigned cSharedPages = 0;
static unsigned cPrivatePages = 0;
/**
* Registers a new module with the VMM
* @param pModule Module ptr
*/
{
bool fFirstLine = true;
unsigned uPageState, uLastPageState;
bool fLastWritable = false;
do
{
bool fShared;
#ifdef RT_ARCH_X86
#else
#endif
if (RT_FAILURE(rc))
if (RT_SUCCESS(rc))
{
if (uPageFlags & X86_PTE_P)
{
if (uPageFlags & X86_PTE_RW)
{
}
else
if (fShared)
{
cSharedPages++;
}
else
{
}
}
else
{
}
if ( !fFirstLine
&& uPageState != uLastPageState)
{
}
if (uPageState != uLastPageState)
{
switch (uPageState)
{
case PAGE_STATE_READ_WRITE:
break;
case PAGE_STATE_SHARED:
break;
case PAGE_STATE_READ_ONLY:
break;
case PAGE_STATE_NOT_PRESENT:
break;
}
fFirstLine = false;
}
}
else
if (!fFirstLine)
{
fFirstLine = true;
}
if (dwModuleSize > PAGE_SIZE)
else
dwModuleSize = 0;
}
while (dwModuleSize);
return;
}
/**
* Inspect all loaded modules for the specified process
* @param dwProcessId Process id
*/
{
if (hSnapshot == INVALID_HANDLE_VALUE)
{
printf("VBoxServicePageSharingInspectModules: CreateToolhelp32Snapshot failed with %d\n", GetLastError());
return;
}
printf("VBoxServicePageSharingInspectModules\n");
do
{
/** todo when changing this make sure VBoxService.exe is excluded! */
if ( pszDot
continue; /* ignore executables for now. */
}
}
/**
* Inspect all running processes for executables and dlls that might be worth sharing
* with other VMs.
*
*/
{
printf("\n\nUSER RESULTS\n");
cNotPresentPages = 0;
cWritablePages = 0;
cPrivatePages = 0;
cSharedPages = 0;
/* Check all loaded kernel modules. */
{
if (!cbBuffer)
{
printf("ZwQuerySystemInformation returned length 0\n");
goto skipkernelmodules;
}
if (!pBuffer)
goto skipkernelmodules;
if (ret != 0)
{
goto skipkernelmodules;
}
for (unsigned i = 0; i < pSystemModules->NumberOfModules; i++)
{
/* User-mode modules seem to have no flags set; skip them as we detected them above. */
continue;
/* New module; register it. */
char szFullFilePath[512];
strcpy(ModuleInfo.szModule, &pSystemModules->Modules[i].FullPathName[pSystemModules->Modules[i].OffsetToFileName]);
/* skip \Systemroot\system32 */
if (!lpPath)
{
break;
}
if (!lpPath)
{
break;
}
}
if (pBuffer)
}
printf("\n\nKERNEL RESULTS\n");
}
#else
{
/* @todo other platforms */
}
#endif
/** @copydoc VBOXSERVICE::pfnInit */
static DECLCALLBACK(int) VBoxServicePageSharingInit(void)
{
printf("VBoxServicePageSharingInit\n");
#ifdef RT_OS_WINDOWS
if (hNtdll)
ZwQuerySystemInformation = (PFNZWQUERYSYSTEMINFORMATION)GetProcAddress(hNtdll, "ZwQuerySystemInformation");
#endif
/* @todo report system name and version */
/* Never fail here. */
return VINF_SUCCESS;
}
static DECLCALLBACK(void) VBoxServicePageSharingTerm(void)
{
printf("VBoxServicePageSharingTerm\n");
#ifdef RT_OS_WINDOWS
if (hNtdll)
#endif
return;
}
{
int rc = VINF_SUCCESS;
/*
* Init globals and such.
*/
RTR3Init();
/*
* Connect to the kernel part before daemonizing so we can fail
* and complain if there is some kind of problem. We need to initialize
* the guest lib *before* we do the pre-init just in case one of services
* needs do to some initial stuff with it.
*/
printf("Calling VbgR3Init()\n");
rc = VbglR3Init();
if (RT_FAILURE(rc))
{
return -1;
}
return 0;
}