VBoxServiceBalloon.cpp revision a516a177c93895d267f4a4f12b0fc200c5fee618
/* $Id: $ */
/** @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 "VBoxTray.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};
{
Log(("VBoxMemBalloonInit: Init\n"));
gCtx.uMemBalloonSize = 0;
/* Check balloon size */
if (DeviceIoControl(gVBoxDriver, VBOXGUEST_IOCTL_CTL_CHECK_BALLOON_MASK, NULL, 0, &dwMemBalloonSize, sizeof(dwMemBalloonSize), &cbReturned, NULL))
{
}
else
*pfStartThread = true;
*ppInstance = &gCtx;
return VINF_SUCCESS;
}
{
Log(("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, VBOXGUEST_IOCTL_CTL_FILTER_MASK, &maskInfo, sizeof (maskInfo), NULL, 0, &cbReturned, NULL))
{
Log(("VBoxMemBalloonThread: DeviceIOControl(CtlMask - or) succeeded\n"));
}
else
{
Log(("VBoxMemBalloonThread: DeviceIOControl(CtlMask) failed, SeamlessChangeThread exited\n"));
return 0;
}
do
{
/* wait for a seamless change event */
if (DeviceIoControl(gVBoxDriver, VBOXGUEST_IOCTL_WAITEVENT, &waitEvent, sizeof(waitEvent), &waitEvent, sizeof(waitEvent), &cbReturned, NULL))
{
Log(("VBoxMemBalloonThread: DeviceIOControl succeded\n"));
/* are we supposed to stop? */
break;
Log(("VBoxMemBalloonThread: checking event\n"));
/* did we get the right event? */
{
if (DeviceIoControl(gVBoxDriver, VBOXGUEST_IOCTL_CTL_CHECK_BALLOON_MASK, NULL, 0, &dwMemBalloonSize, sizeof(dwMemBalloonSize), &cbReturned, NULL))
{
}
else
}
}
else
{
Log(("VBoxMemBalloonThread: error 0 from DeviceIoControl VBOXGUEST_IOCTL_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, VBOXGUEST_IOCTL_CTL_FILTER_MASK, &maskInfo, sizeof (maskInfo), NULL, 0, &cbReturned, NULL))
{
Log(("VBoxMemBalloonThread: DeviceIOControl(CtlMask - not) succeeded\n"));
}
else
{
Log(("VBoxMemBalloonThread: DeviceIOControl(CtlMask) failed\n"));
}
Log(("VBoxMemBalloonThread: finished mem balloon change request thread\n"));
return 0;
}