[WIN32K:NTUSER] For processes that start without any window station and no desktops...
authorHermès Bélusca-Maïto <hermes.belusca-maito@reactos.org>
Sun, 22 Jul 2018 22:15:23 +0000 (00:15 +0200)
committerHermès Bélusca-Maïto <hermes.belusca-maito@reactos.org>
Sun, 19 Aug 2018 20:18:41 +0000 (22:18 +0200)
win32ss/user/ntuser/desktop.c

index ad070ad..4cfdde9 100644 (file)
@@ -3210,6 +3210,39 @@ IntSetThreadDesktop(IN HDESK hDesktop,
         }
     }
 
+    /*
+     * Processes, in particular Winlogon.exe, that manage window stations
+     * (especially the interactive WinSta0 window station) and desktops,
+     * may not be able to connect at startup to a window station and have
+     * an associated desktop as well, if none exists on the system already.
+     * Because creating a new window station does not affect the window station
+     * associated to the process, and because neither by associating a window
+     * station to the process nor creating a new desktop on it does associate
+     * a startup desktop to that process, the process has to actually assigns
+     * one of its threads to a desktop so that it gets automatically an assigned
+     * startup desktop.
+     *
+     * This is what actually happens for Winlogon.exe, which is started without
+     * any window station and desktop. By creating the first (and therefore
+     * interactive) WinSta0 window station, then assigning WinSta0 to itself
+     * and creating the Default desktop on it, and then assigning this desktop
+     * to its main thread, Winlogon.exe basically does the similar steps that
+     * would have been done automatically at its startup if there were already
+     * an existing WinSta0 window station and Default desktop.
+     *
+     * Of course all this must not be done if we are a SYSTEM or CSRSS thread.
+     */
+    // if (pti->ppi->peProcess != gpepCSRSS)
+    if (!(pti->TIF_flags & (TIF_SYSTEMTHREAD | TIF_CSRSSTHREAD)) &&
+        pti->ppi->rpdeskStartup == NULL && hDesktop != NULL)
+    {
+        ERR("The process 0x%p '%s' didn't have an assigned startup desktop before, assigning it now!\n",
+            pti->ppi->peProcess, pti->ppi->peProcess->ImageFileName);
+
+        pti->ppi->hdeskStartup = hDesktop;
+        pti->ppi->rpdeskStartup = pdesk;
+    }
+
     /* free all classes or move them to the shared heap */
     if (pti->rpdesk != NULL)
     {