Index: /trunk/src/VBox/Additions/common/VBoxService/VBoxServiceControl.cpp
===================================================================
--- /trunk/src/VBox/Additions/common/VBoxService/VBoxServiceControl.cpp	(revision 84208)
+++ /trunk/src/VBox/Additions/common/VBoxService/VBoxServiceControl.cpp	(revision 84209)
@@ -107,4 +107,5 @@
 static int  vgsvcGstCtrlHandleSessionOpen(PVBGLR3GUESTCTRLCMDCTX pHostCtx);
 static int  vgsvcGstCtrlHandleSessionClose(PVBGLR3GUESTCTRLCMDCTX pHostCtx);
+static int  vgsvcGstCtrlInvalidate(void);
 static void vgsvcGstCtrlShutdown(void);
 
@@ -205,28 +206,7 @@
     if (RT_SUCCESS(rc))
     {
-        g_fControlSupportsOptimizations = VbglR3GuestCtrlSupportsOptimizations(g_idControlSvcClient);
-        if (g_fControlSupportsOptimizations)
-            rc = VbglR3GuestCtrlMakeMeMaster(g_idControlSvcClient);
+        rc = vgsvcGstCtrlInvalidate();
         if (RT_SUCCESS(rc))
-        {
-            VGSvcVerbose(3, "Guest control service client ID=%RU32%s\n",
-                         g_idControlSvcClient, g_fControlSupportsOptimizations ? " w/ optimizations" : "");
-
-            /*
-             * Report features to the host.
-             */
-            const uint64_t fGuestFeatures = VBOX_GUESTCTRL_GF_0_SET_SIZE
-                                          | VBOX_GUESTCTRL_GF_0_PROCESS_ARGV0;
-
-            rc = VbglR3GuestCtrlReportFeatures(g_idControlSvcClient, fGuestFeatures, &g_fControlHostFeatures0);
-            if (RT_SUCCESS(rc))
-                VGSvcVerbose(3, "Host features: %#RX64\n", g_fControlHostFeatures0);
-            else
-                VGSvcVerbose(1, "Warning! Feature reporing failed: %Rrc\n", rc);
-
-            return VINF_SUCCESS;
-        }
-        VGSvcError("Failed to become guest control master: %Rrc\n", rc);
-        VbglR3GuestCtrlDisconnect(g_idControlSvcClient);
+            return rc;
     }
     else
@@ -248,4 +228,37 @@
 }
 
+static int vgsvcGstCtrlInvalidate(void)
+{
+    VGSvcVerbose(1, "Invalidating configuration ...\n");
+
+    int rc = VINF_SUCCESS;
+
+    g_fControlSupportsOptimizations = VbglR3GuestCtrlSupportsOptimizations(g_idControlSvcClient);
+    if (g_fControlSupportsOptimizations)
+        rc = VbglR3GuestCtrlMakeMeMaster(g_idControlSvcClient);
+    if (RT_SUCCESS(rc))
+    {
+        VGSvcVerbose(3, "Guest control service client ID=%RU32%s\n",
+                     g_idControlSvcClient, g_fControlSupportsOptimizations ? " w/ optimizations" : "");
+
+        /*
+         * Report features to the host.
+         */
+        const uint64_t fGuestFeatures = VBOX_GUESTCTRL_GF_0_SET_SIZE
+                                      | VBOX_GUESTCTRL_GF_0_PROCESS_ARGV0;
+
+        rc = VbglR3GuestCtrlReportFeatures(g_idControlSvcClient, fGuestFeatures, &g_fControlHostFeatures0);
+        if (RT_SUCCESS(rc))
+            VGSvcVerbose(3, "Host features: %#RX64\n", g_fControlHostFeatures0);
+        else
+            VGSvcVerbose(1, "Warning! Feature reporing failed: %Rrc\n", rc);
+
+        return VINF_SUCCESS;
+    }
+    VGSvcError("Failed to become guest control master: %Rrc\n", rc);
+    VbglR3GuestCtrlDisconnect(g_idControlSvcClient);
+
+    return rc;
+}
 
 /**
@@ -327,6 +340,13 @@
         else if (rc == VERR_VM_RESTORED)
         {
-            VGSvcVerbose(1, "The VM session ID changed (i.e. restored).\n");
+            VGSvcVerbose(1, "The VM session ID changed (i.e. restored)\n");
             int rc2 = VGSvcGstCtrlSessionClose(&g_Session);
+            AssertRC(rc2);
+
+            rc2 = VbglR3GuestCtrlSessionHasChanged(g_idControlSvcClient, g_idControlSession);
+            AssertRC(rc2);
+
+            /* Invalidate the internal state to match the current host we got restored from. */
+            rc2 = vgsvcGstCtrlInvalidate();
             AssertRC(rc2);
         }
Index: /trunk/src/VBox/Additions/common/VBoxService/VBoxServiceControlSession.cpp
===================================================================
--- /trunk/src/VBox/Additions/common/VBoxService/VBoxServiceControlSession.cpp	(revision 84208)
+++ /trunk/src/VBox/Additions/common/VBoxService/VBoxServiceControlSession.cpp	(revision 84209)
@@ -1852,4 +1852,25 @@
 
 /**
+ * Invalidates a guest session by updating all it's internal parameters like host features and stuff.
+ *
+ * @param   pSession            Session to invalidate.
+ * @param   idClient            Client ID to use.
+ */
+static void vgsvcGstCtrlSessionInvalidate(PVBOXSERVICECTRLSESSION pSession, uint32_t idClient)
+{
+    RT_NOREF(pSession);
+
+    VGSvcVerbose(1, "Invalidating session %RU32 (client ID=%RU32)\n", idClient, pSession->StartupInfo.uSessionID);
+
+    int rc2 = VbglR3GuestCtrlQueryFeatures(idClient, &g_fControlHostFeatures0);
+    if (RT_SUCCESS(rc2)) /* Querying host features is not fatal -- do not use rc here. */
+    {
+        VGSvcVerbose(1, "g_fControlHostFeatures0=%#x\n", g_fControlHostFeatures0);
+    }
+    else
+        VGSvcVerbose(1, "Querying host features failed with %Rrc\n", rc2);
+}
+
+/**
  * Main message handler for the guest control session process.
  *
@@ -1873,13 +1894,11 @@
     g_idControlSvcClient            = idClient;
 
-    int rc2 = VbglR3GuestCtrlQueryFeatures(idClient, &g_fControlHostFeatures0);
-    if (RT_FAILURE(rc2)) /* Querying host features is not fatal -- do not use rc here. */
-        VGSvcVerbose(1, "Querying host features failed with %Rrc\n", rc2);
+    VGSvcVerbose(1, "Using client ID=%RU32\n", idClient);
+
+    vgsvcGstCtrlSessionInvalidate(pSession, idClient);
 
     rc = vgsvcGstCtrlSessionReadKeyAndAccept(idClient, pSession->StartupInfo.uSessionID);
     if (RT_SUCCESS(rc))
     {
-        VGSvcVerbose(1, "Using client ID=%RU32, g_fControlHostFeatures0=%#x\n", idClient, g_fControlHostFeatures0);
-
         /*
          * Report started status.
@@ -1927,4 +1946,20 @@
                         /* Let others run (guests are often single CPU) ... */
                         RTThreadYield();
+                    }
+                    /*
+                     * Handle restore notification from host.  All the context IDs (sessions,
+                     * files, proceses, etc) are invalidated by a VM restore and must be closed.
+                     */
+                    else if (rc == VERR_VM_RESTORED)
+                    {
+                        VGSvcVerbose(1, "The VM session ID changed (i.e. restored)\n");
+                        int rc2 = VGSvcGstCtrlSessionClose(&g_Session);
+                        AssertRC(rc2);
+
+                        rc2 = VbglR3GuestCtrlSessionHasChanged(g_idControlSvcClient, g_idControlSvcClient);
+                        AssertRC(rc2);
+
+                        /* Invalidate the internal state to match the current host we got restored from. */
+                        vgsvcGstCtrlSessionInvalidate(pSession, g_idControlSvcClient);
                     }
                     else
