VBoxMemBalloon.cpp revision 4604ab7d38c2bd2dfc255aa1facffdf81c1c9153
/** @file
*
* VBoxMemBalloon - Memory balloon notification
*
*/
/*
* Copyright (C) 2006-2007 Sun Microsystems, Inc.
*
* 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.
*
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
* Clara, CA 95054 USA or visit http://www.sun.com if you need
* additional information or have any questions.
*/
#define _WIN32_WINNT 0x0500
#include <windows.h>
#include <psapi.h>
#include "VBoxService.h"
#include "VBoxMemBalloon.h"
#include <VBoxDisplay.h>
#include <VBoxGuestInternal.h>
#include "helpers.h"
#include <winternl.h>
typedef struct _VBOXMEMBALLOONCONTEXT
{
const VBOXSERVICEENV *pEnv;
static VBOXMEMBALLOONCONTEXT gCtx = {0};
{
dprintf(("VBoxMemBalloonInit\n"));
gCtx.uMemBalloonSize = 0;
/* Check balloon size */
if (DeviceIoControl(gVBoxDriver, IOCTL_VBOXGUEST_CTL_CHECK_BALLOON, NULL, 0, &dwMemBalloonSize, sizeof(dwMemBalloonSize), &cbReturned, NULL))
{
}
else
*pfStartThread = true;
*ppInstance = &gCtx;
return VINF_SUCCESS;
}
{
dprintf(("VBoxMemBalloonDestroy\n"));
return;
}
{
return gCtx.uMemBalloonSize;
}
/**
* Thread function to wait for and process seamless mode change
* requests
*/
{
bool fTerminate = false;
maskInfo.u32NotMask = 0;
if (DeviceIoControl (gVBoxDriver, IOCTL_VBOXGUEST_CTL_FILTER_MASK, &maskInfo, sizeof (maskInfo), NULL, 0, &cbReturned, NULL))
{
dprintf(("VBoxMemBalloonThread: DeviceIOControl(CtlMask - or) succeeded\n"));
}
else
{
dprintf(("VBoxMemBalloonThread: DeviceIOControl(CtlMask) failed, SeamlessChangeThread exited\n"));
return 0;
}
do
{
/* wait for a seamless change event */
if (DeviceIoControl(gVBoxDriver, IOCTL_VBOXGUEST_WAITEVENT, &waitEvent, sizeof(waitEvent), &waitEvent, sizeof(waitEvent), &cbReturned, NULL))
{
dprintf(("VBoxMemBalloonThread: DeviceIOControl succeded\n"));
/* are we supposed to stop? */
break;
dprintf(("VBoxMemBalloonThread: checking event\n"));
/* did we get the right event? */
{
if (DeviceIoControl(gVBoxDriver, IOCTL_VBOXGUEST_CTL_CHECK_BALLOON, NULL, 0, &dwMemBalloonSize, sizeof(dwMemBalloonSize), &cbReturned, NULL))
{
}
else
}
}
else
{
dprintf(("VBoxMemBalloonThread: error 0 from DeviceIoControl IOCTL_VBOXGUEST_WAITEVENT\n"));
/* sleep a bit to not eat too much CPU in case the above call always fails */
{
fTerminate = true;
break;
}
}
}
while (!fTerminate);
if (DeviceIoControl (gVBoxDriver, IOCTL_VBOXGUEST_CTL_FILTER_MASK, &maskInfo, sizeof (maskInfo), NULL, 0, &cbReturned, NULL))
{
dprintf(("VBoxMemBalloonThread: DeviceIOControl(CtlMask - not) succeeded\n"));
}
else
{
dprintf(("VBoxMemBalloonThread: DeviceIOControl(CtlMask) failed\n"));
}
dprintf(("VBoxMemBalloonThread: finished mem balloon change request thread\n"));
return 0;
}