[vbox-dev] Restore Notification

Ross Kinder ross at kndr.org
Tue Mar 9 10:21:04 PST 2010

Hello All,

I'm working on an application built on top of VirtualBox which would
like to be notified when the VM resumes from a snapshot.  After a bit
of digging, I found the VMMDEV_EVENT_RESTORED event, but I'm having a
bit of trouble getting it to work with version 3.1.4 on a Windows XP

Using the VBoxTray application as a guide, I opened a handle to the
guest driver.  The code executes without, but it doesn't seem to be

#define IN_RING3
#include <VBox/VBoxGuest.h>
#include <VBox/VMMDev.h>

// ...

bool RestoreWatcherThread::Main() {
  while (true) {
    DWORD nbytes;
    VBoxGuestFilterMaskInfo mask_args;
    mask_args.u32OrMask = VMMDEV_EVENT_RESTORED;
    mask_args.u32NotMask = 0;

    if (!DeviceIoControl(hDriver, VBOXGUEST_IOCTL_CTL_FILTER_MASK, &mask_args,
        sizeof(mask_args), &mask_args, sizeof(mask_args), &nbytes, NULL)) {
      return false;

    VBoxGuestWaitEventInfo wait_args;
    memset(&wait_args, 0, sizeof(wait_args));
    wait_args.u32TimeoutIn = 5000;
    wait_args.u32EventMaskIn = VMMDEV_EVENT_RESTORED;
    if (!DeviceIoControl(hDriver, VBOXGUEST_IOCTL_WAITEVENT, &wait_args,
        sizeof(wait_args), &wait_args, sizeof(wait_args), &nbytes, NULL)) {
      return false;
    if (wait_args.u32EventFlagsOut & VMMDEV_EVENT_RESTORED) {
      if (!SetEvent(event_.get())) {
        return false;

For testing purposes, I replaced VMMDEV_EVENT_RESTORED with 0xffffffff
events, so I'm pretty sure my code here is working correctly.  Is it
expected that I should be able to receive VMMDEV_EVENT_RESTORED?

I noticed this little tidbit in VMMDev.cpp:VMMDevNotifyGuest:
    252     /*
    253      * Drop notifications if the VM is not running yet/anymore.
    254      */
    255     VMSTATE enmVMState = PDMDevHlpVMState(pDevIns);
    256     if (    enmVMState != VMSTATE_RUNNING
    257         &&  enmVMState != VMSTATE_RUNNING_LS)
    258         return;

and I wonder if this has something to do with it, but I'm not sure.

Any thoughts / guidance would be most welcome.


More information about the vbox-dev mailing list