ReactOS 0.4.16-dev-1946-g52006dd
desktop.c
Go to the documentation of this file.
1/*
2 * COPYRIGHT: See COPYING in the top level directory
3 * PROJECT: ReactOS Win32k subsystem
4 * PURPOSE: Desktops
5 * FILE: subsystems/win32/win32k/ntuser/desktop.c
6 * PROGRAMMER: Casper S. Hornstrup (chorns@users.sourceforge.net)
7 */
8
9/* INCLUDES ******************************************************************/
10
11#include <win32k.h>
13
14#include <reactos/buildno.h>
15
16static NTSTATUS
18
19static NTSTATUS
21
22static NTSTATUS
24
25static VOID
27
28/* GLOBALS *******************************************************************/
29
30/* These can be changed via registry settings.
31 * Default values (interactive desktop / non-interactive desktop):
32 * Windows 2003 x86: 3 MB / 512 KB (Disconnect: 64 KB, Winlogon: 128 KB)
33 * Windows 7 x86: 12 MB / 512 KB
34 * Windows 7 x64: 20 MB / 768 KB
35 * Windows 10 x64: 20 MB / 4 MB
36 * See:
37 * - https://dbmentors.blogspot.com/2011/09/desktop-heap-overview.html
38 * - https://www.ibm.com/support/pages/using-microsoft-desktop-heap-monitor-dheapmon-determine-desktop-heap-space-and-troubleshoot-filenet-p8-and-image-services-issues
39 * - https://www.betaarchive.com/wiki/index.php?title=Microsoft_KB_Archive/184802
40 * - https://kb.firedaemon.com/support/solutions/articles/4000086192-windows-service-quota-limits-and-desktop-heap-exhaustion
41 * - https://learn.microsoft.com/en-us/troubleshoot/windows-server/performance/desktop-heap-limitation-out-of-memory
42 */
43#ifdef _WIN64
44DWORD gdwDesktopSectionSize = 20 * 1024; // 20 MB (Windows 7 style)
45#else
46DWORD gdwDesktopSectionSize = 3 * 1024; // 3 MB (Windows 2003 style)
47#endif
50
51/* Currently active desktop */
57
58/* OBJECT CALLBACKS **********************************************************/
59
67 IN OUT PUNICODE_STRING CompleteName,
72{
76 PLIST_ENTRY NextEntry, ListHead;
77 PWINSTATION_OBJECT WinStaObject = (PWINSTATION_OBJECT)ParseObject;
78 UNICODE_STRING DesktopName;
79 PBOOLEAN pContext = (PBOOLEAN) Context;
80
81 if (pContext)
82 *pContext = FALSE;
83
84 /* Set the list pointers and loop the window station */
85 ListHead = &WinStaObject->DesktopListHead;
86 NextEntry = ListHead->Flink;
87 while (NextEntry != ListHead)
88 {
89 /* Get the current desktop */
90 Desktop = CONTAINING_RECORD(NextEntry, DESKTOP, ListEntry);
91
92 /* Get the desktop name */
93 ASSERT(Desktop->pDeskInfo != NULL);
94 RtlInitUnicodeString(&DesktopName, Desktop->pDeskInfo->szDesktopName);
95
96 /* Compare the name */
98 &DesktopName,
100 {
101 /* We found a match. Did this come from a create? */
102 if (Context)
103 {
104 /* Unless OPEN_IF was given, fail with an error */
105 if (!(Attributes & OBJ_OPENIF))
106 {
107 /* Name collision */
109 }
110 else
111 {
112 /* Otherwise, return with a warning only */
114 }
115 }
116 else
117 {
118 /* This was a real open, so this is OK */
120 }
121
122 /* Reference the desktop and return it */
124 *Object = Desktop;
125 return Status;
126 }
127
128 /* Go to the next desktop */
129 NextEntry = NextEntry->Flink;
130 }
131
132 /* If we got here but this isn't a create, just fail */
134
135 /* Create the desktop object */
141 NULL,
142 sizeof(DESKTOP),
143 0,
144 0,
145 (PVOID*)&Desktop);
146 if (!NT_SUCCESS(Status)) return Status;
147
148 /* Assign security to the desktop we have created */
150 if (!NT_SUCCESS(Status))
151 {
153 return Status;
154 }
155
156 /* Initialize the desktop */
158 if (!NT_SUCCESS(Status))
159 {
161 return Status;
162 }
163
164 /* Set the desktop object and return success */
165 *Object = Desktop;
166 *pContext = TRUE;
167 return STATUS_SUCCESS;
168}
169
171NTAPI
174{
176 PDESKTOP pdesk = (PDESKTOP)DeleteParameters->Object;
177
178 TRACE("Deleting desktop object 0x%p\n", pdesk);
179
180 if (pdesk->pDeskInfo &&
181 pdesk->pDeskInfo->spwnd)
182 {
183 ASSERT(pdesk->pDeskInfo->spwnd->spwndChild == NULL);
185 }
186
187 if (pdesk->spwndMessage)
189
190 /* Remove the desktop from the window station's list of associated desktops */
191 RemoveEntryList(&pdesk->ListEntry);
192
193 /* Free the heap */
194 IntFreeDesktopHeap(pdesk);
195
197
198 return STATUS_SUCCESS;
199}
200
202NTAPI
205{
208
209 if (pti == NULL)
210 {
211 /* This happens when we leak desktop handles */
212 return STATUS_SUCCESS;
213 }
214
215 /* Do not allow the current desktop or the initial desktop to be closed */
216 if (OkToCloseParameters->Handle == pti->ppi->hdeskStartup ||
217 OkToCloseParameters->Handle == pti->hdesk)
218 {
220 }
221
222 return STATUS_SUCCESS;
223}
224
226NTAPI
229{
230 NTSTATUS Ret;
232 PPROCESSINFO ppi = PsGetProcessWin32Process(OpenParameters->Process);
233 if (ppi == NULL)
234 return STATUS_SUCCESS;
235
237 Ret = IntMapDesktopView((PDESKTOP)OpenParameters->Object);
238 UserLeave();
239 return Ret;
240}
241
243NTAPI
246{
247 NTSTATUS Ret;
249 PPROCESSINFO ppi = PsGetProcessWin32Process(CloseParameters->Process);
250 if (ppi == NULL)
251 {
252 /* This happens when the process leaks desktop handles.
253 * At this point the PPROCESSINFO is already destroyed */
254 return STATUS_SUCCESS;
255 }
256
258 Ret = IntUnmapDesktopView((PDESKTOP)CloseParameters->Object);
259 UserLeave();
260 return Ret;
261}
262
263
264/* PRIVATE FUNCTIONS **********************************************************/
265
266CODE_SEG("INIT")
268NTAPI
270{
271 GENERIC_MAPPING IntDesktopMapping = { DESKTOP_READ,
275
276 /* Set Desktop Object Attributes */
278 ExDesktopObjectType->TypeInfo.GenericMapping = IntDesktopMapping;
280
281 /* Allocate memory for the event structure */
283 sizeof(KEVENT),
286 {
287 ERR("Failed to allocate event!\n");
288 return STATUS_NO_MEMORY;
289 }
290
291 /* Initialize the kernel event */
294 FALSE);
295
296 return STATUS_SUCCESS;
297}
298
299static NTSTATUS
302 IN BOOLEAN InSafeMode,
303 IN BOOLEAN AppendNtSystemRoot)
304{
306
307 RTL_OSVERSIONINFOEXW VerInfo;
308 UNICODE_STRING BuildLabString;
309 UNICODE_STRING CSDVersionString;
310 RTL_QUERY_REGISTRY_TABLE VersionConfigurationTable[] =
311 {
312 {
313 NULL,
315 L"BuildLab",
316 &BuildLabString,
317 REG_NONE, NULL, 0
318 },
319 {
320 NULL,
322 L"CSDVersion",
323 &CSDVersionString,
324 REG_NONE, NULL, 0
325 },
326
327 {0}
328 };
329
330 WCHAR BuildLabBuffer[256];
331 WCHAR VersionBuffer[256];
332 PWCHAR EndBuffer;
333
334 VerInfo.dwOSVersionInfoSize = sizeof(VerInfo);
335
336 /*
337 * This call is uniquely used to retrieve the current CSD numbers.
338 * All the rest (major, minor, ...) is either retrieved from the
339 * SharedUserData structure, or from the registry.
340 */
342
343 /*
344 * - Retrieve the BuildLab string from the registry (set by the kernel).
345 * - In kernel-mode, szCSDVersion is not initialized. Initialize it
346 * and query its value from the registry.
347 */
348 RtlZeroMemory(BuildLabBuffer, sizeof(BuildLabBuffer));
349 RtlInitEmptyUnicodeString(&BuildLabString,
350 BuildLabBuffer,
351 sizeof(BuildLabBuffer));
352 RtlZeroMemory(VerInfo.szCSDVersion, sizeof(VerInfo.szCSDVersion));
353 RtlInitEmptyUnicodeString(&CSDVersionString,
354 VerInfo.szCSDVersion,
355 sizeof(VerInfo.szCSDVersion));
357 L"",
358 VersionConfigurationTable,
359 NULL,
360 NULL);
361 if (!NT_SUCCESS(Status))
362 {
363 /* Indicate nothing is there */
364 BuildLabString.Length = 0;
365 CSDVersionString.Length = 0;
366 }
367 /* NULL-terminate the strings */
368 BuildLabString.Buffer[BuildLabString.Length / sizeof(WCHAR)] = UNICODE_NULL;
369 CSDVersionString.Buffer[CSDVersionString.Length / sizeof(WCHAR)] = UNICODE_NULL;
370
371 EndBuffer = VersionBuffer;
372 if ( /* VerInfo.wServicePackMajor != 0 && */ CSDVersionString.Length)
373 {
374 /* Print the version string */
375 Status = RtlStringCbPrintfExW(VersionBuffer,
376 sizeof(VersionBuffer),
377 &EndBuffer,
378 NULL,
379 0,
380 L": %wZ",
381 &CSDVersionString);
382 if (!NT_SUCCESS(Status))
383 {
384 /* No version, NULL-terminate the string */
385 *EndBuffer = UNICODE_NULL;
386 }
387 }
388 else
389 {
390 /* No version, NULL-terminate the string */
391 *EndBuffer = UNICODE_NULL;
392 }
393
394 if (InSafeMode)
395 {
396 /* String for Safe Mode */
397 Status = RtlStringCchPrintfW(pwszzVersion,
398 cchDest,
399 L"ReactOS Version %S %wZ (NT %u.%u Build %u%s)\n",
400 KERNEL_VERSION_STR,
401 &BuildLabString,
402 SharedUserData->NtMajorVersion,
403 SharedUserData->NtMinorVersion,
404 (VerInfo.dwBuildNumber & 0xFFFF),
405 VersionBuffer);
406
407 if (AppendNtSystemRoot && NT_SUCCESS(Status))
408 {
409 Status = RtlStringCbPrintfW(VersionBuffer,
410 sizeof(VersionBuffer),
411 L" - %s\n",
412 SharedUserData->NtSystemRoot);
413 if (NT_SUCCESS(Status))
414 {
415 /* Replace the last newline by a NULL, before concatenating */
416 EndBuffer = wcsrchr(pwszzVersion, L'\n');
417 if (EndBuffer) *EndBuffer = UNICODE_NULL;
418
419 /* The concatenated string has a terminating newline */
420 Status = RtlStringCchCatW(pwszzVersion,
421 cchDest,
422 VersionBuffer);
423 if (!NT_SUCCESS(Status))
424 {
425 /* Concatenation failed, put back the newline */
426 if (EndBuffer) *EndBuffer = L'\n';
427 }
428 }
429
430 /* Override any failures as the NtSystemRoot string is optional */
432 }
433 }
434 else
435 {
436 /* Multi-string for Normal Mode */
437 Status = RtlStringCchPrintfW(pwszzVersion,
438 cchDest,
439 L"ReactOS Version %S\n"
440 L"Build %wZ\n"
441 L"Reporting NT %u.%u (Build %u%s)\n",
442 KERNEL_VERSION_STR,
443 &BuildLabString,
444 SharedUserData->NtMajorVersion,
445 SharedUserData->NtMinorVersion,
446 (VerInfo.dwBuildNumber & 0xFFFF),
447 VersionBuffer);
448
449 if (AppendNtSystemRoot && NT_SUCCESS(Status))
450 {
451 Status = RtlStringCbPrintfW(VersionBuffer,
452 sizeof(VersionBuffer),
453 L"%s\n",
454 SharedUserData->NtSystemRoot);
455 if (NT_SUCCESS(Status))
456 {
457 Status = RtlStringCchCatW(pwszzVersion,
458 cchDest,
459 VersionBuffer);
460 }
461
462 /* Override any failures as the NtSystemRoot string is optional */
464 }
465 }
466
467 if (!NT_SUCCESS(Status))
468 {
469 /* Fall-back string */
470 Status = RtlStringCchPrintfW(pwszzVersion,
471 cchDest,
472 L"ReactOS Version %S %wZ\n",
473 KERNEL_VERSION_STR,
474 &BuildLabString);
475 if (!NT_SUCCESS(Status))
476 {
477 /* General failure, NULL-terminate the string */
478 pwszzVersion[0] = UNICODE_NULL;
479 }
480 }
481
482 /*
483 * Convert the string separators (newlines) into NULLs
484 * and NULL-terminate the multi-string.
485 */
486 while (*pwszzVersion)
487 {
488 EndBuffer = wcschr(pwszzVersion, L'\n');
489 if (!EndBuffer) break;
490 pwszzVersion = EndBuffer;
491
492 *pwszzVersion++ = UNICODE_NULL;
493 }
494 *pwszzVersion = UNICODE_NULL;
495
496 return Status;
497}
498
499
500/*
501 * IntResolveDesktop
502 *
503 * The IntResolveDesktop function attempts to retrieve valid handles to
504 * a desktop and a window station suitable for the specified process.
505 * The specified desktop path string is used only as a hint for the resolution.
506 *
507 * - If the process is already assigned to a window station and a desktop,
508 * handles to these objects are returned directly regardless of the specified
509 * desktop path string. This is what happens when this function is called for
510 * a process that has been already started and connected to the Win32 USER.
511 *
512 * - If the process is being connected to the Win32 USER, or is in a state
513 * where a window station is assigned to it but no desktop yet, the desktop
514 * path string is used as a hint for the resolution.
515 * A specified window station (if any, otherwise "WinSta0" is used as default)
516 * is tested for existence and accessibility. If the checks are OK a handle
517 * to it is returned. Otherwise we either fail (the window station does not
518 * exist) or, in case a default window station was used, we attempt to open
519 * or create a non-interactive Service-0xXXXX-YYYY$ window station. This is
520 * typically what happens when a non-interactive process is started while
521 * the WinSta0 window station was used as the default one.
522 * A specified desktop (if any, otherwise "Default" is used as default)
523 * is then tested for existence on the opened window station.
524 *
525 * - Rules for the choice of the default window station, when none is specified
526 * in the desktop path:
527 *
528 * 1. By default, a SYSTEM process connects to a non-interactive window
529 * station, either the Service-0x0-3e7$ (from the SYSTEM LUID) station,
530 * or one that has been inherited and that is non-interactive.
531 * Only when the interactive window station WinSta0 is specified that
532 * the process can connect to it (e.g. the case of interactive services).
533 *
534 * 2. An interactive process, i.e. a process whose LUID is the same as the
535 * one assigned to WinSta0 by Winlogon on user logon, connects by default
536 * to the WinSta0 window station, unless it has inherited from another
537 * interactive window station (which must be... none other than WinSta0).
538 *
539 * 3. A non-interactive (but not SYSTEM) process connects by default to
540 * a non-interactive Service-0xXXXX-YYYY$ window station (whose name
541 * is derived from the process' LUID), or to another non-interactive
542 * window station that has been inherited.
543 * Otherwise it may be able connect to the interactive WinSta0 only if
544 * it has explicit access rights to it.
545 *
546 * Parameters
547 * Process
548 * The user process object.
549 *
550 * DesktopPath
551 * The desktop path string used as a hint for desktop resolution.
552 *
553 * bInherit
554 * Whether or not the returned handles are inheritable.
555 *
556 * phWinSta
557 * Pointer to a window station handle.
558 *
559 * phDesktop
560 * Pointer to a desktop handle.
561 *
562 * Return Value
563 * Status code.
564 */
565
570 IN PUNICODE_STRING DesktopPath,
571 IN BOOL bInherit,
572 OUT HWINSTA* phWinSta,
573 OUT HDESK* phDesktop)
574{
576 HWINSTA hWinSta = NULL, hWinStaDup = NULL;
577 HDESK hDesktop = NULL, hDesktopDup = NULL;
578 PPROCESSINFO ppi;
580 LUID ProcessLuid;
581 USHORT StrSize;
582 SIZE_T MemSize;
583 PSECURITY_DESCRIPTOR ServiceSD;
586 UNICODE_STRING WinStaName, DesktopName;
587 const UNICODE_STRING WinSta0Name = RTL_CONSTANT_STRING(L"WinSta0");
588 PWINSTATION_OBJECT WinStaObject;
589 HWINSTA hTempWinSta = NULL;
590 BOOLEAN bUseDefaultWinSta = FALSE;
591 BOOLEAN bInteractive = FALSE;
592 BOOLEAN bAccessAllowed = FALSE;
593
595
596 ASSERT(phWinSta);
597 ASSERT(phDesktop);
598 ASSERT(DesktopPath);
599
600 *phWinSta = NULL;
601 *phDesktop = NULL;
602
604 /* ppi is typically NULL for console applications that connect to Win32 USER */
605 if (!ppi) TRACE("IntResolveDesktop: ppi is NULL!\n");
606
607 if (ppi && ppi->hwinsta != NULL && ppi->hdeskStartup != NULL)
608 {
609 /*
610 * If this process is the current one, just return the cached handles.
611 * Otherwise, open the window station and desktop objects.
612 */
614 {
615 hWinSta = ppi->hwinsta;
616 hDesktop = ppi->hdeskStartup;
617 }
618 else
619 {
621 0,
622 NULL,
625 UserMode,
626 (PHANDLE)&hWinSta);
627 if (!NT_SUCCESS(Status))
628 {
629 ERR("IntResolveDesktop: Could not reference window station 0x%p\n", ppi->prpwinsta);
631 return Status;
632 }
633
635 0,
636 NULL,
639 UserMode,
640 (PHANDLE)&hDesktop);
641 if (!NT_SUCCESS(Status))
642 {
643 ERR("IntResolveDesktop: Could not reference desktop 0x%p\n", ppi->rpdeskStartup);
644 ObCloseHandle(hWinSta, UserMode);
646 return Status;
647 }
648 }
649
650 *phWinSta = hWinSta;
651 *phDesktop = hDesktop;
652 return STATUS_SUCCESS;
653 }
654
655 /* We will by default use the default window station and desktop */
656 RtlInitEmptyUnicodeString(&WinStaName, NULL, 0);
657 RtlInitEmptyUnicodeString(&DesktopName, NULL, 0);
658
659 /*
660 * Parse the desktop path string which can be of the form "WinSta\Desktop"
661 * or just "Desktop". In the latter case we use the default window station
662 * on which the process is attached to (or if none, "WinSta0").
663 */
664 if (DesktopPath->Buffer != NULL && DesktopPath->Length > sizeof(WCHAR))
665 {
666 DesktopName = *DesktopPath;
667
668 /* Find the separator */
669 while (DesktopName.Length > 0 && *DesktopName.Buffer &&
670 *DesktopName.Buffer != OBJ_NAME_PATH_SEPARATOR)
671 {
672 DesktopName.Buffer++;
673 DesktopName.Length -= sizeof(WCHAR);
674 DesktopName.MaximumLength -= sizeof(WCHAR);
675 }
676 if (DesktopName.Length > 0)
677 {
678 RtlInitEmptyUnicodeString(&WinStaName, DesktopPath->Buffer,
679 DesktopPath->Length - DesktopName.Length);
680 // (USHORT)((ULONG_PTR)DesktopName.Buffer - (ULONG_PTR)DesktopPath->Buffer);
681 WinStaName.Length = WinStaName.MaximumLength;
682
683 /* Skip the separator */
684 DesktopName.Buffer++;
685 DesktopName.Length -= sizeof(WCHAR);
686 DesktopName.MaximumLength -= sizeof(WCHAR);
687 }
688 else
689 {
690 RtlInitEmptyUnicodeString(&WinStaName, NULL, 0);
691 DesktopName = *DesktopPath;
692 }
693 }
694
695 TRACE("IntResolveDesktop: WinStaName:'%wZ' ; DesktopName:'%wZ'\n", &WinStaName, &DesktopName);
696
697 /* Retrieve the process LUID */
698 Status = GetProcessLuid(NULL, Process, &ProcessLuid);
699 if (!NT_SUCCESS(Status))
700 {
701 ERR("IntResolveDesktop: Failed to retrieve the process LUID, Status 0x%08lx\n", Status);
703 return Status;
704 }
705
706 /*
707 * If this process is not the current one, obtain a temporary handle
708 * to it so that we can perform handles duplication later.
709 */
711 {
714 NULL,
715 0,
718 &hProcess);
719 if (!NT_SUCCESS(Status))
720 {
721 ERR("IntResolveDesktop: Failed to obtain a handle to process 0x%p, Status 0x%08lx\n", Process, Status);
723 return Status;
724 }
726 }
727
728 /*
729 * If no window station has been specified, search the process handle table
730 * for inherited window station handles, otherwise use a default one.
731 */
732 if (WinStaName.Buffer == NULL)
733 {
734 /*
735 * We want to find a suitable default window station.
736 * For applications that can be interactive, i.e. that have allowed
737 * access to the single interactive window station on the system,
738 * the default window station is 'WinSta0'.
739 * For applications that cannot be interactive, i.e. that do not have
740 * access to 'WinSta0' (e.g. non-interactive services), the default
741 * window station is 'Service-0xXXXX-YYYY$' (created if needed).
742 * Precedence will however be taken by any inherited window station
743 * that possesses the required interactivity property.
744 */
745 bUseDefaultWinSta = TRUE;
746
747 /*
748 * Use the default 'WinSta0' window station. Whether we should
749 * use 'Service-0xXXXX-YYYY$' instead will be determined later.
750 */
751 // RtlInitUnicodeString(&WinStaName, L"WinSta0");
752 WinStaName = WinSta0Name;
753
755 NULL,
757 NULL,
758 (PHANDLE)&hWinSta))
759 {
760 TRACE("IntResolveDesktop: Inherited window station is: 0x%p\n", hWinSta);
761 }
762 }
763
764 /*
765 * If no desktop has been specified, search the process handle table
766 * for inherited desktop handles, otherwise use the Default desktop.
767 * Note that the inherited desktop that we may use, may not belong
768 * to the window station we will connect to.
769 */
770 if (DesktopName.Buffer == NULL)
771 {
772 /* Use a default desktop name */
773 RtlInitUnicodeString(&DesktopName, L"Default");
774
776 NULL,
778 NULL,
779 (PHANDLE)&hDesktop))
780 {
781 TRACE("IntResolveDesktop: Inherited desktop is: 0x%p\n", hDesktop);
782 }
783 }
784
785
786 /*
787 * We are going to open either a window station or a desktop.
788 * Even if this operation is done from kernel-mode, we should
789 * "emulate" an opening from user-mode (i.e. using an ObjectAttributes
790 * allocated in user-mode, with AccessMode == UserMode) for the
791 * Object Manager to perform proper access validation to the
792 * window station or desktop.
793 */
794
795 /*
796 * Estimate the maximum size needed for the window station name
797 * and desktop name to be given to ObjectAttributes->ObjectName.
798 */
799 StrSize = 0;
800
801 /* Window station name */
802 MemSize = _scwprintf(L"Service-0x%x-%x$", MAXULONG, MAXULONG) * sizeof(WCHAR);
804 + max(WinStaName.Length, MemSize) + sizeof(UNICODE_NULL);
805 if (MemSize > MAXUSHORT)
806 {
807 ERR("IntResolveDesktop: Window station name length is too long.\n");
809 goto Quit;
810 }
811 StrSize = max(StrSize, (USHORT)MemSize);
812
813 /* Desktop name */
814 MemSize = max(DesktopName.Length + sizeof(UNICODE_NULL), sizeof(L"Default"));
815 StrSize = max(StrSize, (USHORT)MemSize);
816
817 /* Size for the OBJECT_ATTRIBUTES */
818 MemSize = ALIGN_UP(sizeof(OBJECT_ATTRIBUTES), sizeof(PVOID));
819
820 /* Add the string size */
821 MemSize += ALIGN_UP(sizeof(UNICODE_STRING), sizeof(PVOID));
822 MemSize += StrSize;
823
824 /* Allocate the memory in user-mode */
825 Status = ZwAllocateVirtualMemory(ZwCurrentProcess(),
827 0,
828 &MemSize,
831 if (!NT_SUCCESS(Status))
832 {
833 ERR("ZwAllocateVirtualMemory() failed, Status 0x%08lx\n", Status);
834 goto Quit;
835 }
836
838 ALIGN_UP(sizeof(OBJECT_ATTRIBUTES), sizeof(PVOID)));
839
840 RtlInitEmptyUnicodeString(ObjectName,
842 ALIGN_UP(sizeof(UNICODE_STRING), sizeof(PVOID))),
843 StrSize);
844
845
846 /* If we got an inherited window station handle, duplicate and use it */
847 if (hWinSta)
848 {
849 ASSERT(bUseDefaultWinSta);
850
851 /* Duplicate the handle if it belongs to another process than the current one */
853 {
855 Status = ZwDuplicateObject(hProcess,
856 hWinSta,
858 (PHANDLE)&hWinStaDup,
859 0,
860 0,
862 if (!NT_SUCCESS(Status))
863 {
864 ERR("IntResolveDesktop: Failed to duplicate the window station handle, Status 0x%08lx\n", Status);
865 /* We will use a default window station */
866 hWinSta = NULL;
867 }
868 else
869 {
870 hWinSta = hWinStaDup;
871 }
872 }
873 }
874
875 /*
876 * If we have an inherited window station, check whether
877 * it is interactive and remember that for later.
878 */
879 if (hWinSta)
880 {
881 ASSERT(bUseDefaultWinSta);
882
883 /* Reference the inherited window station */
885 0,
888 (PVOID*)&WinStaObject,
889 NULL);
890 if (!NT_SUCCESS(Status))
891 {
892 ERR("Failed to reference the inherited window station, Status 0x%08lx\n", Status);
893 /* We will use a default window station */
894 if (hWinStaDup)
895 {
896 ASSERT(hWinSta == hWinStaDup);
897 ObCloseHandle(hWinStaDup, UserMode);
898 hWinStaDup = NULL;
899 }
900 hWinSta = NULL;
901 }
902 else
903 {
904 ERR("Process LUID is: 0x%x-%x, inherited window station LUID is: 0x%x-%x\n",
905 ProcessLuid.HighPart, ProcessLuid.LowPart,
906 WinStaObject->luidUser.HighPart, WinStaObject->luidUser.LowPart);
907
908 /* Check whether this window station is interactive, and remember it for later */
909 bInteractive = !(WinStaObject->Flags & WSS_NOIO);
910
911 /* Dereference the window station */
912 ObDereferenceObject(WinStaObject);
913 }
914 }
915
916 /* Build a valid window station name */
918 ObjectName->MaximumLength,
919 L"%wZ\\%wZ",
921 &WinStaName);
922 if (!NT_SUCCESS(Status))
923 {
924 ERR("Impossible to build a valid window station name, Status 0x%08lx\n", Status);
925 goto Quit;
926 }
927 ObjectName->Length = (USHORT)(wcslen(ObjectName->Buffer) * sizeof(WCHAR));
928
929 TRACE("Parsed initial window station: '%wZ'\n", ObjectName);
930
931 /* Try to open the window station */
935 NULL,
936 NULL);
937 if (bInherit)
938 ObjectAttributes->Attributes |= OBJ_INHERIT;
939
942 UserMode,
943 NULL,
945 NULL,
946 (PHANDLE)&hTempWinSta);
947 if (!NT_SUCCESS(Status))
948 {
949 ERR("Failed to open the window station '%wZ', Status 0x%08lx\n", ObjectName, Status);
950 }
951 else
952 {
953 //
954 // FIXME TODO: Perform a window station access check!!
955 // If we fail AND bUseDefaultWinSta == FALSE we just quit.
956 //
957
958 /*
959 * Check whether we are opening the (single) interactive
960 * window station, and if so, perform an access check.
961 */
962 /* Check whether we are allowed to perform interactions */
963 if (RtlEqualUnicodeString(&WinStaName, &WinSta0Name, TRUE))
964 {
965 LUID SystemLuid = SYSTEM_LUID;
966
967 /* Interactive window station: check for user LUID */
968 WinStaObject = InputWindowStation;
969
971
972 // TODO: Check also that we compare wrt. window station WinSta0
973 // which is the only one that can be interactive on the system.
974 if (((!bUseDefaultWinSta || bInherit) && RtlEqualLuid(&ProcessLuid, &SystemLuid)) ||
975 RtlEqualLuid(&ProcessLuid, &WinStaObject->luidUser))
976 {
977 /* We are interactive on this window station */
978 bAccessAllowed = TRUE;
980 }
981 }
982 else
983 {
984 /* Non-interactive window station: we have access since we were able to open it */
985 bAccessAllowed = TRUE;
987 }
988 }
989
990 /* If we failed, bail out if we were not trying to open the default window station */
991 if (!NT_SUCCESS(Status) && !bUseDefaultWinSta) // if (!bAccessAllowed)
992 goto Quit;
993
994 if (/* bAccessAllowed && */ bInteractive || !bAccessAllowed)
995 {
996 /*
997 * Close WinSta0 if the inherited window station is interactive so that
998 * we can use it, or we do not have access to the interactive WinSta0.
999 */
1000 ObCloseHandle(hTempWinSta, UserMode);
1001 hTempWinSta = NULL;
1002 }
1003 if (bInteractive == bAccessAllowed)
1004 {
1005 /* Keep using the inherited window station */
1006 NOTHING;
1007 }
1008 else // if (bInteractive != bAccessAllowed)
1009 {
1010 /*
1011 * Close the inherited window station, we will either keep using
1012 * the interactive WinSta0, or use Service-0xXXXX-YYYY$.
1013 */
1014 if (hWinStaDup)
1015 {
1016 ASSERT(hWinSta == hWinStaDup);
1017 ObCloseHandle(hWinStaDup, UserMode);
1018 hWinStaDup = NULL;
1019 }
1020 hWinSta = hTempWinSta; // hTempWinSta is NULL in case bAccessAllowed == FALSE
1021 }
1022
1023 if (bUseDefaultWinSta)
1024 {
1025 if (hWinSta == NULL && !bInteractive)
1026 {
1027 /* Build a valid window station name from the LUID */
1029 ObjectName->MaximumLength,
1030 L"%wZ\\Service-0x%x-%x$",
1032 ProcessLuid.HighPart,
1033 ProcessLuid.LowPart);
1034 if (!NT_SUCCESS(Status))
1035 {
1036 ERR("Impossible to build a valid window station name, Status 0x%08lx\n", Status);
1037 goto Quit;
1038 }
1039 ObjectName->Length = (USHORT)(wcslen(ObjectName->Buffer) * sizeof(WCHAR));
1040
1041 /*
1042 * Set up a security descriptor for the new service's window station.
1043 * A service has an associated window station and desktop. The newly
1044 * created window station and desktop will get this security descriptor
1045 * if such objects weren't created before.
1046 */
1047 Status = IntCreateServiceSecurity(&ServiceSD);
1048 if (!NT_SUCCESS(Status))
1049 {
1050 ERR("Failed to create a security descriptor for service window station, Status 0x%08lx\n", Status);
1051 goto Quit;
1052 }
1053
1054 /*
1055 * Create or open the non-interactive window station.
1056 * NOTE: The non-interactive window station handle is never inheritable.
1057 */
1059 ObjectName,
1061 NULL,
1062 ServiceSD);
1063
1064 Status = IntCreateWindowStation(&hWinSta,
1066 UserMode,
1067 KernelMode,
1069 0, 0, 0, 0, 0);
1070
1071 IntFreeSecurityBuffer(ServiceSD);
1072
1073 if (!NT_SUCCESS(Status))
1074 {
1075 ASSERT(hWinSta == NULL);
1076 ERR("Failed to create or open the non-interactive window station '%wZ', Status 0x%08lx\n",
1078 goto Quit;
1079 }
1080
1081 //
1082 // FIXME: We might not need to always create or open the "Default"
1083 // desktop on the Service-0xXXXX-YYYY$ window station; we may need
1084 // to use another one....
1085 //
1086
1087 /* Create or open the Default desktop on the window station */
1089 ObjectName->MaximumLength,
1090 L"Default");
1091 if (!NT_SUCCESS(Status))
1092 {
1093 ERR("Impossible to build a valid desktop name, Status 0x%08lx\n", Status);
1094 goto Quit;
1095 }
1096 ObjectName->Length = (USHORT)(wcslen(ObjectName->Buffer) * sizeof(WCHAR));
1097
1098 /*
1099 * NOTE: The non-interactive desktop handle is never inheritable.
1100 * The security descriptor is inherited from the newly created
1101 * window station for the desktop.
1102 */
1104 ObjectName,
1106 hWinSta,
1107 NULL);
1108
1109 Status = IntCreateDesktop(&hDesktop,
1111 UserMode,
1112 NULL,
1113 NULL,
1114 0,
1116 if (!NT_SUCCESS(Status))
1117 {
1118 ASSERT(hDesktop == NULL);
1119 ERR("Failed to create or open the desktop '%wZ' on window station 0x%p, Status 0x%08lx\n",
1120 ObjectName, hWinSta, Status);
1121 }
1122
1123 goto Quit;
1124 }
1125/*
1126 if (hWinSta == NULL)
1127 {
1128 Status = STATUS_UNSUCCESSFUL;
1129 goto Quit;
1130 }
1131*/
1132 }
1133
1134 /*
1135 * If we got an inherited desktop handle, duplicate and use it,
1136 * otherwise open a new desktop.
1137 */
1138 if (hDesktop != NULL)
1139 {
1140 /* Duplicate the handle if it belongs to another process than the current one */
1142 {
1144 Status = ZwDuplicateObject(hProcess,
1145 hDesktop,
1147 (PHANDLE)&hDesktopDup,
1148 0,
1149 0,
1151 if (!NT_SUCCESS(Status))
1152 {
1153 ERR("IntResolveDesktop: Failed to duplicate the desktop handle, Status 0x%08lx\n", Status);
1154 /* We will use a default desktop */
1155 hDesktop = NULL;
1156 }
1157 else
1158 {
1159 hDesktop = hDesktopDup;
1160 }
1161 }
1162 }
1163
1164 if ((hWinSta != NULL) && (hDesktop == NULL))
1165 {
1167 ObjectName->MaximumLength,
1168 DesktopName.Buffer,
1169 DesktopName.Length);
1170 if (!NT_SUCCESS(Status))
1171 {
1172 ERR("Impossible to build a valid desktop name, Status 0x%08lx\n", Status);
1173 goto Quit;
1174 }
1175 ObjectName->Length = (USHORT)(wcslen(ObjectName->Buffer) * sizeof(WCHAR));
1176
1177 TRACE("Parsed initial desktop: '%wZ'\n", ObjectName);
1178
1179 /* Open the desktop object */
1181 ObjectName,
1183 hWinSta,
1184 NULL);
1185 if (bInherit)
1186 ObjectAttributes->Attributes |= OBJ_INHERIT;
1187
1190 UserMode,
1191 NULL,
1193 NULL,
1194 (PHANDLE)&hDesktop);
1195 if (!NT_SUCCESS(Status))
1196 {
1197 ERR("Failed to open the desktop '%wZ' on window station 0x%p, Status 0x%08lx\n",
1198 ObjectName, hWinSta, Status);
1199 goto Quit;
1200 }
1201 }
1202
1203Quit:
1204 /* Release the object attributes */
1205 if (ObjectAttributes)
1206 {
1207 MemSize = 0;
1208 ZwFreeVirtualMemory(ZwCurrentProcess(),
1210 &MemSize,
1211 MEM_RELEASE);
1212 }
1213
1214 /* Close the temporary process handle */
1215 if (hProcess) // if (Process != PsGetCurrentProcess())
1217
1218 if (NT_SUCCESS(Status))
1219 {
1220 *phWinSta = hWinSta;
1221 *phDesktop = hDesktop;
1222 return STATUS_SUCCESS;
1223 }
1224 else
1225 {
1226 ERR("IntResolveDesktop(%wZ) failed, Status 0x%08lx\n", DesktopPath, Status);
1227
1228 if (hDesktopDup)
1229 ObCloseHandle(hDesktopDup, UserMode);
1230 if (hWinStaDup)
1231 ObCloseHandle(hWinStaDup, UserMode);
1232
1233 if (hDesktop)
1234 ObCloseHandle(hDesktop, UserMode);
1235 if (hWinSta)
1236 ObCloseHandle(hWinSta, UserMode);
1237
1239 return Status;
1240 }
1241}
1242
1243/*
1244 * IntValidateDesktopHandle
1245 *
1246 * Validates the desktop handle.
1247 *
1248 * Remarks
1249 * If the function succeeds, the handle remains referenced. If the
1250 * fucntion fails, last error is set.
1251 */
1252
1255 HDESK Desktop,
1259{
1261
1265 AccessMode,
1266 (PVOID*)Object,
1267 NULL);
1268
1269 TRACE("IntValidateDesktopHandle: handle:0x%p obj:0x%p access:0x%x Status:0x%lx\n",
1271
1272 if (!NT_SUCCESS(Status))
1274
1275 return Status;
1276}
1277
1280{
1281 return gpdeskInputDesktop;
1282}
1283
1284/*
1285 * Returns or creates a handle to the desktop object
1286 */
1287HDESK FASTCALL
1289{
1291 HDESK hDesk;
1292
1293 ASSERT(DesktopObject);
1294
1296 DesktopObject,
1298 NULL,
1299 (PHANDLE)&hDesk))
1300 {
1301 Status = ObOpenObjectByPointer(DesktopObject,
1302 0,
1303 NULL,
1304 0,
1306 UserMode,
1307 (PHANDLE)&hDesk);
1308 if (!NT_SUCCESS(Status))
1309 {
1310 /* Unable to create a handle */
1311 ERR("Unable to create a desktop handle\n");
1312 return NULL;
1313 }
1314 }
1315 else
1316 {
1317 TRACE("Got handle: 0x%p\n", hDesk);
1318 }
1319
1320 return hDesk;
1321}
1322
1325{
1327 if (!pdo)
1328 {
1329 TRACE("No active desktop\n");
1330 return(NULL);
1331 }
1333}
1334
1337{
1340 if (!pdo)
1341 {
1342 TRACE("No active desktop\n");
1343 return;
1344 }
1345 if (NewQueue != NULL)
1346 {
1347 if (NewQueue->Desktop != NULL)
1348 {
1349 TRACE("Message Queue already attached to another desktop!\n");
1350 return;
1351 }
1352 IntReferenceMessageQueue(NewQueue);
1353 (void)InterlockedExchangePointer((PVOID*)&NewQueue->Desktop, pdo);
1354 }
1356 if (Old != NULL)
1357 {
1359 gpqForegroundPrev = Old;
1361 }
1362 // Only one Q can have active foreground even when there are more than one desktop.
1363 if (NewQueue)
1364 {
1366 }
1367 else
1368 {
1370 ERR("ptiLastInput is CLEARED!!\n");
1371 ptiLastInput = NULL; // ReactOS hacks... should check for process death.
1372 }
1373}
1374
1377{
1378 if (!pti) pti = PsGetCurrentThreadWin32Thread();
1379 if (pti->pDeskInfo) return pti->pDeskInfo->spwnd;
1380 return NULL;
1381}
1382
1384{
1385 if (pWnd->head.rpdesk &&
1386 pWnd->head.rpdesk->pDeskInfo)
1387 return pWnd->head.rpdesk->pDeskInfo->spwnd;
1388 return NULL;
1389}
1390
1392{
1394 if (!pdo)
1395 {
1396 TRACE("No active desktop\n");
1397 return NULL;
1398 }
1399 return pdo->DesktopWindow;
1400}
1401
1402// Win: _GetDesktopWindow
1404{
1406 if (!pdo)
1407 {
1408 TRACE("No active desktop\n");
1409 return NULL;
1410 }
1411 // return pdo->pDeskInfo->spwnd;
1413}
1414
1416{
1418 if (!pdo)
1419 {
1420 TRACE("No active desktop\n");
1421 return NULL;
1422 }
1423 return UserHMGetHandle(pdo->spwndMessage);
1424}
1425
1426// Win: _GetMessageWindow
1428{
1430 if (!pdo)
1431 {
1432 TRACE("No active desktop\n");
1433 return NULL;
1434 }
1435 return pdo->spwndMessage;
1436}
1437
1439{
1441 PDESKTOP pdo = pti->rpdesk;
1442 if (!pdo)
1443 {
1444 ERR("Thread doesn't have a desktop\n");
1445 return NULL;
1446 }
1447 return pdo->DesktopWindow;
1448}
1449
1450/* PUBLIC FUNCTIONS ***********************************************************/
1451
1454{
1455 PAINTSTRUCT Ps;
1456 ULONG Value;
1457 //ERR("DesktopWindowProc\n");
1458
1459 *lResult = 0;
1460
1461 switch (Msg)
1462 {
1463 case WM_NCCREATE:
1464 if (!Wnd->fnid)
1465 {
1466 Wnd->fnid = FNID_DESKTOP;
1467 }
1468 *lResult = (LRESULT)TRUE;
1469 return TRUE;
1470
1471 case WM_CREATE:
1473 // Save Process ID
1476 // Save Thread ID
1478 case WM_CLOSE:
1479 return TRUE;
1480
1481 case WM_DISPLAYCHANGE:
1483 return TRUE;
1484
1485 case WM_ERASEBKGND:
1487 *lResult = 1;
1488 return TRUE;
1489
1490 case WM_PAINT:
1491 {
1492 if (IntBeginPaint(Wnd, &Ps))
1493 {
1494 IntEndPaint(Wnd, &Ps);
1495 }
1496 return TRUE;
1497 }
1498 case WM_SYSCOLORCHANGE:
1500 return TRUE;
1501
1502 case WM_SETCURSOR:
1503 {
1504 PCURICON_OBJECT pcurOld, pcurNew;
1506 if (!pcurNew)
1507 {
1508 return TRUE;
1509 }
1510
1511 pcurNew->CURSORF_flags |= CURSORF_CURRENT;
1512 pcurOld = UserSetCursor(pcurNew, FALSE);
1513 if (pcurOld)
1514 {
1515 pcurOld->CURSORF_flags &= ~CURSORF_CURRENT;
1516 UserDereferenceObject(pcurOld);
1517 }
1518 return TRUE;
1519 }
1520
1522 {
1523 PWINDOWPOS pWindowPos = (PWINDOWPOS)lParam;
1524 if ((pWindowPos->flags & SWP_SHOWWINDOW) != 0)
1525 {
1527 IntSetThreadDesktop(hdesk, FALSE);
1528 }
1529 break;
1530 }
1531 default:
1532 TRACE("DWP calling IDWP Msg %d\n",Msg);
1533 //*lResult = IntDefWindowProc(Wnd, Msg, wParam, lParam, FALSE);
1534 }
1535 return TRUE; /* We are done. Do not do any callbacks to user mode */
1536}
1537
1540{
1541 *lResult = 0;
1542
1543 switch(Msg)
1544 {
1545 case WM_NCCREATE:
1546 pwnd->fnid |= FNID_MESSAGEWND;
1547 *lResult = (LRESULT)TRUE;
1548 break;
1549 case WM_DESTROY:
1550 pwnd->fnid |= FNID_DESTROY;
1551 break;
1552 default:
1553 ERR("UMWP calling IDWP\n");
1554 *lResult = IntDefWindowProc(pwnd, Msg, wParam, lParam, FALSE);
1555 }
1556
1557 return TRUE; /* We are done. Do not do any callbacks to user mode */
1558}
1559
1561{
1562 BOOL Ret;
1563 MSG Msg;
1564
1566
1568
1569 /* Register system classes. This thread does not belong to any desktop so the
1570 classes will be allocated from the shared heap */
1572
1574
1575 while (TRUE)
1576 {
1577 Ret = co_IntGetPeekMessage(&Msg, 0, 0, 0, PM_REMOVE, TRUE);
1578 if (Ret)
1579 {
1581 }
1582 }
1583
1584 UserLeave();
1585}
1586
1588UserGetDesktopDC(ULONG DcType, BOOL bAltDc, BOOL ValidatehWnd)
1589{
1590 PWND DesktopObject = 0;
1591 HDC DesktopHDC = 0;
1592
1593 /* This can be called from GDI/DX, so acquire the USER lock */
1595
1596 if (DcType == DCTYPE_DIRECT)
1597 {
1598 DesktopObject = UserGetDesktopWindow();
1599 DesktopHDC = (HDC)UserGetWindowDC(DesktopObject);
1600 }
1601 else
1602 {
1603 PMONITOR pMonitor = UserGetPrimaryMonitor();
1604 DesktopHDC = IntGdiCreateDisplayDC(pMonitor->hDev, DcType, bAltDc);
1605 }
1606
1607 UserLeave();
1608
1609 return DesktopHDC;
1610}
1611
1614{
1615 PWND Window = NULL;
1616 PREGION Rgn;
1617
1619 Rgn = IntSysCreateRectpRgnIndirect(&Window->rcWindow);
1620
1622 Rgn,
1625
1626 REGION_Delete(Rgn);
1627}
1628
1629
1632{
1633 PWND pwnd = Desktop->pDeskInfo->spwnd;
1635 ASSERT(pwnd);
1636
1637 if (!bRedraw)
1639
1641
1642 if (bRedraw)
1644
1645 return STATUS_SUCCESS;
1646}
1647
1650{
1651 PWND DesktopWnd;
1652
1653 DesktopWnd = IntGetWindowObject(Desktop->DesktopWindow);
1654 if (! DesktopWnd)
1655 {
1657 }
1658 DesktopWnd->style &= ~WS_VISIBLE;
1659
1660 return STATUS_SUCCESS;
1661}
1662
1663static
1666{
1667 ULONG entries=0;
1668 PLIST_ENTRY ListEntry;
1669 PSHELL_HOOK_WINDOW Current;
1670 HWND* list;
1671
1672 /* FIXME: If we save nb elements in desktop, we don't have to loop to find nb entries */
1673 ListEntry = Desktop->ShellHookWindows.Flink;
1674 while (ListEntry != &Desktop->ShellHookWindows)
1675 {
1676 ListEntry = ListEntry->Flink;
1677 entries++;
1678 }
1679
1680 if (!entries) return NULL;
1681
1682 list = ExAllocatePoolWithTag(PagedPool, sizeof(HWND) * (entries + 1), USERTAG_WINDOWLIST); /* alloc one extra for nullterm */
1683 if (list)
1684 {
1685 HWND* cursor = list;
1686
1687 ListEntry = Desktop->ShellHookWindows.Flink;
1688 while (ListEntry != &Desktop->ShellHookWindows)
1689 {
1690 Current = CONTAINING_RECORD(ListEntry, SHELL_HOOK_WINDOW, ListEntry);
1691 ListEntry = ListEntry->Flink;
1692 *cursor++ = Current->hWnd;
1693 }
1694
1695 *cursor = NULL; /* Nullterm list */
1696 }
1697
1698 return list;
1699}
1700
1701/*
1702 * Send the Message to the windows registered for ShellHook
1703 * notifications. The lParam contents depend on the Message. See
1704 * MSDN for more details (RegisterShellHookWindow)
1705 */
1707{
1709 HWND* HwndList;
1710
1711 if (!gpsi->uiShellMsg)
1712 {
1713 gpsi->uiShellMsg = IntAddAtom(L"SHELLHOOK");
1714
1715 TRACE("MsgType = %x\n", gpsi->uiShellMsg);
1716 if (!gpsi->uiShellMsg)
1717 ERR("LastError: %x\n", EngGetLastError());
1718 }
1719
1720 if (!Desktop)
1721 {
1722 TRACE("IntShellHookNotify: No desktop!\n");
1723 return;
1724 }
1725
1726 // Allow other devices have a shot at foreground.
1727 if (Message == HSHELL_APPCOMMAND) ptiLastInput = NULL;
1728
1729 // FIXME: System Tray Support.
1730
1732 if (HwndList)
1733 {
1734 HWND* cursor = HwndList;
1735 LPARAM shellhookparam = (Message == HSHELL_LANGUAGE || Message == HSHELL_APPCOMMAND)
1736 ? lParam : (LPARAM)wParam;
1737
1738 for (; *cursor; cursor++)
1739 {
1740 TRACE("Sending notify\n");
1743 Message,
1744 shellhookparam);
1745/* co_IntPostOrSendMessage(*cursor,
1746 gpsi->uiShellMsg,
1747 Message,
1748 shellhookparam);*/
1749 }
1750
1752 }
1753
1754 if (ISITHOOKED(WH_SHELL))
1755 {
1757 }
1758}
1759
1760/*
1761 * Add the window to the ShellHookWindows list. The windows
1762 * on that list get notifications that are important to shell
1763 * type applications.
1764 *
1765 * TODO: Validate the window? I'm not sure if sending these messages to
1766 * an unsuspecting application that is not your own is a nice thing to do.
1767 */
1769{
1771 PDESKTOP Desktop = pti->rpdesk;
1773
1774 TRACE("IntRegisterShellHookWindow\n");
1775
1776 /* First deregister the window, so we can be sure it's never twice in the
1777 * list.
1778 */
1780
1782 sizeof(SHELL_HOOK_WINDOW),
1783 TAG_WINSTA);
1784
1785 if (!Entry)
1786 return FALSE;
1787
1788 Entry->hWnd = hWnd;
1789
1790 InsertTailList(&Desktop->ShellHookWindows, &Entry->ListEntry);
1791
1792 return TRUE;
1793}
1794
1795/*
1796 * Remove the window from the ShellHookWindows list. The windows
1797 * on that list get notifications that are important to shell
1798 * type applications.
1799 */
1801{
1803 PDESKTOP Desktop = pti->rpdesk;
1804 PLIST_ENTRY ListEntry;
1805 PSHELL_HOOK_WINDOW Current;
1806
1807 // FIXME: This probably shouldn't happen, but it does
1808 if (Desktop == NULL)
1809 {
1811 if (Desktop == NULL)
1812 return FALSE;
1813 }
1814
1815 ListEntry = Desktop->ShellHookWindows.Flink;
1816 while (ListEntry != &Desktop->ShellHookWindows)
1817 {
1818 Current = CONTAINING_RECORD(ListEntry, SHELL_HOOK_WINDOW, ListEntry);
1819 ListEntry = ListEntry->Flink;
1820 if (Current->hWnd == hWnd)
1821 {
1822 RemoveEntryList(&Current->ListEntry);
1823 ExFreePoolWithTag(Current, TAG_WINSTA);
1824 return TRUE;
1825 }
1826 }
1827
1828 return FALSE;
1829}
1830
1831static VOID
1833{
1834 /* FIXME: Disable until unmapping works in mm */
1835#if 0
1836 if (Desktop->pheapDesktop != NULL)
1837 {
1838 MmUnmapViewInSessionSpace(Desktop->pheapDesktop);
1839 Desktop->pheapDesktop = NULL;
1840 }
1841
1842 if (Desktop->hsectionDesktop != NULL)
1843 {
1844 ObDereferenceObject(Desktop->hsectionDesktop);
1845 Desktop->hsectionDesktop = NULL;
1846 }
1847#endif
1848}
1849
1852{
1853 static WCHAR s_wszSafeMode[] = L"Safe Mode"; // FIXME: Localize!
1854
1855 RECTL Rect;
1856 HBRUSH DesktopBrush, PreviousBrush;
1857 HWND hWndDesktop;
1858 BOOL doPatBlt = TRUE;
1859 PWND WndDesktop;
1860 BOOLEAN InSafeMode;
1861
1862 if (GdiGetClipBox(hDC, &Rect) == ERROR)
1863 return FALSE;
1864
1865 hWndDesktop = IntGetDesktopWindow(); // rpdesk->DesktopWindow;
1866
1867 WndDesktop = UserGetWindowObject(hWndDesktop); // rpdesk->pDeskInfo->spwnd;
1868 if (!WndDesktop)
1869 return FALSE;
1870
1871 /* Retrieve the current SafeMode state */
1872 InSafeMode = (UserGetSystemMetrics(SM_CLEANBOOT) != 0); // gpsi->aiSysMet[SM_CLEANBOOT];
1873
1874 if (!InSafeMode)
1875 {
1876 DesktopBrush = (HBRUSH)WndDesktop->pcls->hbrBackground;
1877
1878 /*
1879 * Paint desktop background
1880 */
1882 {
1883 SIZE sz;
1884 int x, y;
1885 int scaledWidth, scaledHeight;
1886 int wallpaperX, wallpaperY, wallpaperWidth, wallpaperHeight;
1887 HDC hWallpaperDC;
1888
1889 sz.cx = WndDesktop->rcWindow.right - WndDesktop->rcWindow.left;
1890 sz.cy = WndDesktop->rcWindow.bottom - WndDesktop->rcWindow.top;
1891
1892 if (gspv.WallpaperMode == wmFit ||
1894 {
1895 int scaleNum, scaleDen;
1896
1897 // Precision improvement over ((sz.cx / gspv.cxWallpaper) > (sz.cy / gspv.cyWallpaper))
1898 if ((sz.cx * gspv.cyWallpaper) > (sz.cy * gspv.cxWallpaper))
1899 {
1900 if (gspv.WallpaperMode == wmFit)
1901 {
1902 scaleNum = sz.cy;
1903 scaleDen = gspv.cyWallpaper;
1904 }
1905 else
1906 {
1907 scaleNum = sz.cx;
1908 scaleDen = gspv.cxWallpaper;
1909 }
1910 }
1911 else
1912 {
1913 if (gspv.WallpaperMode == wmFit)
1914 {
1915 scaleNum = sz.cx;
1916 scaleDen = gspv.cxWallpaper;
1917 }
1918 else
1919 {
1920 scaleNum = sz.cy;
1921 scaleDen = gspv.cyWallpaper;
1922 }
1923 }
1924
1925 scaledWidth = EngMulDiv(gspv.cxWallpaper, scaleNum, scaleDen);
1926 scaledHeight = EngMulDiv(gspv.cyWallpaper, scaleNum, scaleDen);
1927
1928 if (gspv.WallpaperMode == wmFill)
1929 {
1930 wallpaperX = (((scaledWidth - sz.cx) * gspv.cxWallpaper) / (2 * scaledWidth));
1931 wallpaperY = (((scaledHeight - sz.cy) * gspv.cyWallpaper) / (2 * scaledHeight));
1932
1933 wallpaperWidth = (sz.cx * gspv.cxWallpaper) / scaledWidth;
1934 wallpaperHeight = (sz.cy * gspv.cyWallpaper) / scaledHeight;
1935 }
1936 }
1937
1938 if (gspv.WallpaperMode == wmStretch ||
1941 {
1942 x = 0;
1943 y = 0;
1944 }
1945 else if (gspv.WallpaperMode == wmFit)
1946 {
1947 x = (sz.cx - scaledWidth) / 2;
1948 y = (sz.cy - scaledHeight) / 2;
1949 }
1950 else
1951 {
1952 /* Find the upper left corner, can be negative if the bitmap is bigger than the screen */
1953 x = (sz.cx / 2) - (gspv.cxWallpaper / 2);
1954 y = (sz.cy / 2) - (gspv.cyWallpaper / 2);
1955 }
1956
1957 hWallpaperDC = NtGdiCreateCompatibleDC(hDC);
1958 if (hWallpaperDC != NULL)
1959 {
1960 HBITMAP hOldBitmap;
1961
1962 /* Fill in the area that the bitmap is not going to cover */
1963 if (x > 0 || y > 0)
1964 {
1965 /* FIXME: Clip out the bitmap
1966 can be replaced with "NtGdiPatBlt(hDC, x, y, gspv.cxWallpaper, gspv.cyWallpaper, PATCOPY | DSTINVERT);"
1967 once we support DSTINVERT */
1968 PreviousBrush = NtGdiSelectBrush(hDC, DesktopBrush);
1969 NtGdiPatBlt(hDC, Rect.left, Rect.top, Rect.right, Rect.bottom, PATCOPY);
1970 NtGdiSelectBrush(hDC, PreviousBrush);
1971 }
1972
1973 /* Do not fill the background after it is painted no matter the size of the picture */
1974 doPatBlt = FALSE;
1975
1976 hOldBitmap = NtGdiSelectBitmap(hWallpaperDC, gspv.hbmWallpaper);
1977
1979 {
1980 if (Rect.right && Rect.bottom)
1982 x,
1983 y,
1984 sz.cx,
1985 sz.cy,
1986 hWallpaperDC,
1987 0,
1988 0,
1991 SRCCOPY,
1992 0);
1993 }
1994 else if (gspv.WallpaperMode == wmTile)
1995 {
1996 /* Paint the bitmap across the screen then down */
1997 for (y = 0; y < Rect.bottom; y += gspv.cyWallpaper)
1998 {
1999 for (x = 0; x < Rect.right; x += gspv.cxWallpaper)
2000 {
2002 x,
2003 y,
2006 hWallpaperDC,
2007 0,
2008 0,
2009 SRCCOPY,
2010 0,
2011 0);
2012 }
2013 }
2014 }
2015 else if (gspv.WallpaperMode == wmFit)
2016 {
2017 if (Rect.right && Rect.bottom)
2018 {
2020 x,
2021 y,
2022 scaledWidth,
2023 scaledHeight,
2024 hWallpaperDC,
2025 0,
2026 0,
2029 SRCCOPY,
2030 0);
2031 }
2032 }
2033 else if (gspv.WallpaperMode == wmFill)
2034 {
2035 if (Rect.right && Rect.bottom)
2036 {
2038 x,
2039 y,
2040 sz.cx,
2041 sz.cy,
2042 hWallpaperDC,
2043 wallpaperX,
2044 wallpaperY,
2045 wallpaperWidth,
2046 wallpaperHeight,
2047 SRCCOPY,
2048 0);
2049 }
2050 }
2051 else
2052 {
2054 x,
2055 y,
2058 hWallpaperDC,
2059 0,
2060 0,
2061 SRCCOPY,
2062 0,
2063 0);
2064 }
2065 NtGdiSelectBitmap(hWallpaperDC, hOldBitmap);
2066 NtGdiDeleteObjectApp(hWallpaperDC);
2067 }
2068 }
2069 }
2070 else
2071 {
2072 /* Black desktop background in Safe Mode */
2073 DesktopBrush = StockObjects[BLACK_BRUSH];
2074 }
2075
2076 /* Background is set to none, clear the screen */
2077 if (doPatBlt)
2078 {
2079 PreviousBrush = NtGdiSelectBrush(hDC, DesktopBrush);
2080 NtGdiPatBlt(hDC, Rect.left, Rect.top, Rect.right, Rect.bottom, PATCOPY);
2081 NtGdiSelectBrush(hDC, PreviousBrush);
2082 }
2083
2084 /*
2085 * Display the system version on the desktop background
2086 */
2087 if (InSafeMode || g_AlwaysDisplayVersion || g_PaintDesktopVersion)
2088 {
2090 static WCHAR wszzVersion[1024] = L"\0";
2091
2092 /* Only used in normal mode */
2093 // We expect at most 4 strings (3 for version, 1 for optional NtSystemRoot)
2094 static POLYTEXTW VerStrs[4] = {{0},{0},{0},{0}};
2095 INT i = 0;
2096 SIZE_T len;
2097
2098 HFONT hFont1 = NULL, hFont2 = NULL, hOldFont = NULL;
2099 COLORREF crText, color_old;
2100 UINT align_old;
2101 INT mode_old;
2102 PDC pdc;
2103
2104 if (!UserSystemParametersInfo(SPI_GETWORKAREA, 0, &Rect, 0))
2105 {
2106 Rect.left = Rect.top = 0;
2109 }
2110 else
2111 {
2112 RECTL_vOffsetRect(&Rect, -Rect.left, -Rect.top);
2113 }
2114
2115 /*
2116 * Set up the fonts (otherwise use default ones)
2117 */
2118
2119 /* Font for the principal version string */
2120 hFont1 = GreCreateFontIndirectW(&gspv.ncm.lfCaptionFont);
2121 /* Font for the secondary version strings */
2122 hFont2 = GreCreateFontIndirectW(&gspv.ncm.lfMenuFont);
2123
2124 if (hFont1)
2125 hOldFont = NtGdiSelectFont(hDC, hFont1);
2126
2127 if (gspv.hbmWallpaper == NULL)
2128 {
2129 /* Retrieve the brush fill colour */
2130 // TODO: The following code constitutes "GreGetBrushColor".
2131 PreviousBrush = NtGdiSelectBrush(hDC, DesktopBrush);
2132 pdc = DC_LockDc(hDC);
2133 if (pdc)
2134 {
2135 crText = pdc->eboFill.ulRGBColor;
2136 DC_UnlockDc(pdc);
2137 }
2138 else
2139 {
2140 crText = RGB(0, 0, 0);
2141 }
2142 NtGdiSelectBrush(hDC, PreviousBrush);
2143
2144 /* Adjust text colour according to the brush */
2145 if (GetRValue(crText) + GetGValue(crText) + GetBValue(crText) > 128 * 3)
2146 crText = RGB(0, 0, 0);
2147 else
2148 crText = RGB(255, 255, 255);
2149 }
2150 else
2151 {
2152 /* Always use white when the text is displayed on top of a wallpaper */
2153 crText = RGB(255, 255, 255);
2154 }
2155
2156 color_old = IntGdiSetTextColor(hDC, crText);
2157 align_old = IntGdiSetTextAlign(hDC, TA_RIGHT);
2158 mode_old = IntGdiSetBkMode(hDC, TRANSPARENT);
2159
2160 /* Display the system version information */
2161 if (!*wszzVersion)
2162 {
2163 Status = GetSystemVersionString(wszzVersion,
2164 ARRAYSIZE(wszzVersion),
2165 InSafeMode,
2167 if (!InSafeMode && NT_SUCCESS(Status) && *wszzVersion)
2168 {
2169 PWCHAR pstr = wszzVersion;
2170 for (i = 0; (i < ARRAYSIZE(VerStrs)) && *pstr; ++i)
2171 {
2172 VerStrs[i].n = lstrlenW(pstr);
2173 VerStrs[i].lpstr = pstr;
2174 pstr += (VerStrs[i].n + 1);
2175 }
2176 }
2177 }
2178 else
2179 {
2181 }
2182 if (NT_SUCCESS(Status) && *wszzVersion)
2183 {
2184 if (!InSafeMode)
2185 {
2186 SIZE Size = {0, 0};
2187 LONG TotalHeight = 0;
2188
2189 /* Normal Mode: multiple version information text separated by newlines */
2191
2192 /* Compute the heights of the strings */
2193 if (hFont1) NtGdiSelectFont(hDC, hFont1);
2194 for (i = 0; i < ARRAYSIZE(VerStrs); ++i)
2195 {
2196 if (!VerStrs[i].lpstr || !*VerStrs[i].lpstr || (VerStrs[i].n == 0))
2197 break;
2198
2199 GreGetTextExtentW(hDC, VerStrs[i].lpstr, VerStrs[i].n, &Size, 1);
2200 VerStrs[i].y = Size.cy; // Store the string height
2201 TotalHeight += Size.cy;
2202
2203 /* While the first string was using hFont1, all the others use hFont2 */
2204 if (hFont2) NtGdiSelectFont(hDC, hFont2);
2205 }
2206 /* The total height must not exceed the screen height */
2207 TotalHeight = min(TotalHeight, Rect.bottom);
2208
2209 /* Display the strings */
2210 if (hFont1) NtGdiSelectFont(hDC, hFont1);
2211 for (i = 0; i < ARRAYSIZE(VerStrs); ++i)
2212 {
2213 if (!VerStrs[i].lpstr || !*VerStrs[i].lpstr || (VerStrs[i].n == 0))
2214 break;
2215
2216 TotalHeight -= VerStrs[i].y;
2218 Rect.right - 5,
2219 Rect.bottom - TotalHeight - 5,
2220 0, NULL,
2221 VerStrs[i].lpstr,
2222 VerStrs[i].n,
2223 NULL, 0);
2224
2225 /* While the first string was using hFont1, all the others use hFont2 */
2226 if (hFont2) NtGdiSelectFont(hDC, hFont2);
2227 }
2228 }
2229 else
2230 {
2231 if (hFont1) NtGdiSelectFont(hDC, hFont1);
2232
2233 /* Safe Mode: single version information text in top center */
2234 len = wcslen(wszzVersion);
2235
2237 GreExtTextOutW(hDC, (Rect.right + Rect.left)/2, Rect.top + 3, 0, NULL, wszzVersion, len, NULL, 0);
2238 }
2239 }
2240
2241 if (InSafeMode)
2242 {
2243 if (hFont1) NtGdiSelectFont(hDC, hFont1);
2244
2245 /* Print Safe Mode text in corners */
2246 len = wcslen(s_wszSafeMode);
2247
2249 GreExtTextOutW(hDC, Rect.left, Rect.top + 3, 0, NULL, s_wszSafeMode, len, NULL, 0);
2251 GreExtTextOutW(hDC, Rect.right, Rect.top + 3, 0, NULL, s_wszSafeMode, len, NULL, 0);
2253 GreExtTextOutW(hDC, Rect.left, Rect.bottom - 5, 0, NULL, s_wszSafeMode, len, NULL, 0);
2255 GreExtTextOutW(hDC, Rect.right, Rect.bottom - 5, 0, NULL, s_wszSafeMode, len, NULL, 0);
2256 }
2257
2258 IntGdiSetBkMode(hDC, mode_old);
2259 IntGdiSetTextAlign(hDC, align_old);
2260 IntGdiSetTextColor(hDC, color_old);
2261
2262 if (hFont2)
2263 GreDeleteObject(hFont2);
2264
2265 if (hFont1)
2266 {
2267 NtGdiSelectFont(hDC, hOldFont);
2268 GreDeleteObject(hFont1);
2269 }
2270 }
2271
2272 return TRUE;
2273}
2274
2275static NTSTATUS
2277{
2278 static const UNICODE_STRING WinlogonDesktop = RTL_CONSTANT_STRING(L"Winlogon");
2279 PVOID DesktopHeapSystemBase = NULL;
2281 SIZE_T DesktopInfoSize;
2282 ULONG i;
2283
2284 TRACE("UserInitializeDesktop desktop 0x%p with name %wZ\n", pdesk, DesktopName);
2285
2286 RtlZeroMemory(pdesk, sizeof(DESKTOP));
2287
2288 /* Set desktop size, based on whether the WinSta is interactive or not */
2289 if (pwinsta == InputWindowStation)
2290 {
2291 /* Check if the Desktop is named "Winlogon" */
2292 if (RtlEqualUnicodeString(DesktopName, &WinlogonDesktop, TRUE))
2293 {
2295 }
2296 else
2297 {
2299 }
2300 }
2301 else
2302 {
2304 }
2305
2306 /* Link the desktop with the parent window station */
2307 ObReferenceObject(pwinsta);
2308 pdesk->rpwinstaParent = pwinsta;
2309 InsertTailList(&pwinsta->DesktopListHead, &pdesk->ListEntry);
2310
2311 /* Create the desktop heap */
2312 pdesk->hsectionDesktop = NULL;
2314 &DesktopHeapSystemBase,
2315 HeapSize);
2316 if (pdesk->pheapDesktop == NULL)
2317 {
2318 ERR("Failed to create desktop heap!\n");
2319 return STATUS_NO_MEMORY;
2320 }
2321
2322 /* Create DESKTOPINFO */
2323 DesktopInfoSize = sizeof(DESKTOPINFO) + DesktopName->Length + sizeof(WCHAR);
2324 pdesk->pDeskInfo = RtlAllocateHeap(pdesk->pheapDesktop,
2326 DesktopInfoSize);
2327 if (pdesk->pDeskInfo == NULL)
2328 {
2329 ERR("Failed to create the DESKTOP structure!\n");
2330 return STATUS_NO_MEMORY;
2331 }
2332
2333 /* Initialize the DESKTOPINFO */
2334 pdesk->pDeskInfo->pvDesktopBase = DesktopHeapSystemBase;
2335 pdesk->pDeskInfo->pvDesktopLimit = (PVOID)((ULONG_PTR)DesktopHeapSystemBase + HeapSize);
2337 DesktopName->Buffer,
2338 DesktopName->Length + sizeof(WCHAR));
2339 for (i = 0; i < NB_HOOKS; i++)
2340 {
2342 }
2343
2345 InitializeListHead(&pdesk->PtiList);
2346
2347 return STATUS_SUCCESS;
2348}
2349
2350/* SYSCALLS *******************************************************************/
2351
2352/*
2353 * NtUserCreateDesktop
2354 *
2355 * Creates a new desktop.
2356 *
2357 * Parameters
2358 * poaAttribs
2359 * Object Attributes.
2360 *
2361 * lpszDesktopDevice
2362 * Name of the device.
2363 *
2364 * pDeviceMode
2365 * Device Mode.
2366 *
2367 * dwFlags
2368 * Interaction flags.
2369 *
2370 * dwDesiredAccess
2371 * Requested type of access.
2372 *
2373 *
2374 * Return Value
2375 * If the function succeeds, the return value is a handle to the newly
2376 * created desktop. If the specified desktop already exists, the function
2377 * succeeds and returns a handle to the existing desktop. When you are
2378 * finished using the handle, call the CloseDesktop function to close it.
2379 * If the function fails, the return value is NULL.
2380 *
2381 * Status
2382 * @implemented
2383 */
2384
2388 OUT HDESK* phDesktop,
2391 IN PUNICODE_STRING lpszDesktopDevice OPTIONAL,
2392 IN LPDEVMODEW lpdmw OPTIONAL,
2394 IN ACCESS_MASK dwDesiredAccess)
2395{
2397 PDESKTOP pdesk = NULL;
2398 HDESK hDesk;
2400 UNICODE_STRING ClassName;
2401 LARGE_STRING WindowName;
2402 BOOL NoHooks = FALSE;
2403 PWND pWnd = NULL;
2404 CREATESTRUCTW Cs;
2405 PTHREADINFO ptiCurrent;
2406 PCLS pcls;
2407
2408 TRACE("Enter IntCreateDesktop\n");
2409
2411
2412 ASSERT(phDesktop);
2413 *phDesktop = NULL;
2414
2415 ptiCurrent = PsGetCurrentThreadWin32Thread();
2416 ASSERT(ptiCurrent);
2418
2419 /* Turn off hooks when calling any CreateWindowEx from inside win32k */
2420 NoHooks = (ptiCurrent->TIF_flags & TIF_DISABLEHOOKS);
2421 ptiCurrent->TIF_flags |= TIF_DISABLEHOOKS;
2422 ptiCurrent->pClientInfo->dwTIFlags = ptiCurrent->TIF_flags;
2423
2424 /*
2425 * Try to open already existing desktop
2426 */
2429 AccessMode,
2430 NULL,
2431 dwDesiredAccess,
2432 (PVOID)&Context,
2433 (PHANDLE)&hDesk);
2434 if (!NT_SUCCESS(Status))
2435 {
2436 ERR("ObOpenObjectByName failed to open/create desktop\n");
2437 goto Quit;
2438 }
2439
2440 /* In case the object was not created (eg if it existed), return now */
2441 if (Context == FALSE)
2442 {
2443 TRACE("IntCreateDesktop opened desktop '%wZ'\n", ObjectAttributes->ObjectName);
2445 goto Quit;
2446 }
2447
2448 /* Reference the desktop */
2450 0,
2452 KernelMode,
2453 (PVOID*)&pdesk,
2454 NULL);
2455 if (!NT_SUCCESS(Status))
2456 {
2457 ERR("Failed to reference desktop object\n");
2458 goto Quit;
2459 }
2460
2461 /* Get the desktop window class. The thread desktop does not belong to any desktop
2462 * so the classes created there (including the desktop class) are allocated in the shared heap
2463 * It would cause problems if we used a class that belongs to the caller
2464 */
2465 ClassName.Buffer = WC_DESKTOP;
2466 ClassName.Length = 0;
2467 pcls = IntGetAndReferenceClass(&ClassName, 0, TRUE);
2468 if (pcls == NULL)
2469 {
2470 ASSERT(FALSE);
2472 goto Quit;
2473 }
2474
2475 RtlZeroMemory(&WindowName, sizeof(WindowName));
2476 RtlZeroMemory(&Cs, sizeof(Cs));
2482 Cs.hInstance = hModClient; // hModuleWin; // Server side winproc!
2483 Cs.lpszName = (LPCWSTR) &WindowName;
2484 Cs.lpszClass = (LPCWSTR) &ClassName;
2485
2486 /* Use IntCreateWindow instead of co_UserCreateWindowEx because the later expects a thread with a desktop */
2487 pWnd = IntCreateWindow(&Cs, &WindowName, pcls, NULL, NULL, NULL, pdesk, WINVER);
2488 if (pWnd == NULL)
2489 {
2490 ERR("Failed to create desktop window for the new desktop\n");
2492 goto Quit;
2493 }
2494
2496 pdesk->DesktopWindow = UserHMGetHandle(pWnd);
2497 pdesk->pDeskInfo->spwnd = pWnd;
2498 pWnd->fnid = FNID_DESKTOP;
2499
2500 ClassName.Buffer = MAKEINTATOM(gpsi->atomSysClass[ICLS_HWNDMESSAGE]);
2501 ClassName.Length = 0;
2502 pcls = IntGetAndReferenceClass(&ClassName, 0, TRUE);
2503 if (pcls == NULL)
2504 {
2505 ASSERT(FALSE);
2507 goto Quit;
2508 }
2509
2510 RtlZeroMemory(&WindowName, sizeof(WindowName));
2511 RtlZeroMemory(&Cs, sizeof(Cs));
2512 Cs.cx = Cs.cy = 100;
2514 Cs.hInstance = hModClient; // hModuleWin; // Server side winproc!
2515 Cs.lpszName = (LPCWSTR)&WindowName;
2516 Cs.lpszClass = (LPCWSTR)&ClassName;
2517 pWnd = IntCreateWindow(&Cs, &WindowName, pcls, NULL, NULL, NULL, pdesk, WINVER);
2518 if (pWnd == NULL)
2519 {
2520 ERR("Failed to create message window for the new desktop\n");
2522 goto Quit;
2523 }
2524
2525 pdesk->spwndMessage = pWnd;
2526 pWnd->fnid = FNID_MESSAGEWND;
2527
2528 /* Now...
2529 if !(WinStaObject->Flags & WSF_NOIO) is (not set) for desktop input output mode (see wiki)
2530 Create Tooltip. Saved in DesktopObject->spwndTooltip.
2531 Tooltip dwExStyle: WS_EX_TOOLWINDOW|WS_EX_TOPMOST
2532 hWndParent are spwndMessage. Use hModuleWin for server side winproc!
2533 The rest is same as message window.
2534 https://learn.microsoft.com/en-us/windows/win32/controls/tooltip-controls
2535 */
2537
2538Quit:
2539 if (pdesk != NULL)
2540 {
2541 ObDereferenceObject(pdesk);
2542 }
2543 if (!NT_SUCCESS(Status) && hDesk != NULL)
2544 {
2545 ObCloseHandle(hDesk, AccessMode);
2546 hDesk = NULL;
2547 }
2548 if (!NoHooks)
2549 {
2550 ptiCurrent->TIF_flags &= ~TIF_DISABLEHOOKS;
2551 ptiCurrent->pClientInfo->dwTIFlags = ptiCurrent->TIF_flags;
2552 }
2553
2554 TRACE("Leave IntCreateDesktop, Status 0x%08lx\n", Status);
2555
2556 if (NT_SUCCESS(Status))
2557 *phDesktop = hDesk;
2558 else
2560 return Status;
2561}
2562
2563HDESK APIENTRY
2566 PUNICODE_STRING lpszDesktopDevice,
2567 LPDEVMODEW lpdmw,
2568 DWORD dwFlags,
2569 ACCESS_MASK dwDesiredAccess)
2570{
2572 HDESK hDesk;
2573 HDESK Ret = NULL;
2574
2575 TRACE("Enter NtUserCreateDesktop\n");
2577
2578 Status = IntCreateDesktop(&hDesk,
2580 UserMode,
2581 lpszDesktopDevice,
2582 lpdmw,
2583 dwFlags,
2584 dwDesiredAccess);
2585 if (!NT_SUCCESS(Status))
2586 {
2587 ERR("IntCreateDesktop failed, Status 0x%08lx\n", Status);
2588 // SetLastNtError(Status);
2589 goto Exit; // Return NULL
2590 }
2591
2592 Ret = hDesk;
2593
2594Exit:
2595 TRACE("Leave NtUserCreateDesktop, ret=0x%p\n", Ret);
2596 UserLeave();
2597 return Ret;
2598}
2599
2600/*
2601 * NtUserOpenDesktop
2602 *
2603 * Opens an existing desktop.
2604 *
2605 * Parameters
2606 * lpszDesktopName
2607 * Name of the existing desktop.
2608 *
2609 * dwFlags
2610 * Interaction flags.
2611 *
2612 * dwDesiredAccess
2613 * Requested type of access.
2614 *
2615 * Return Value
2616 * Handle to the desktop or zero on failure.
2617 *
2618 * Status
2619 * @implemented
2620 */
2621
2622HDESK APIENTRY
2625 DWORD dwFlags,
2626 ACCESS_MASK dwDesiredAccess)
2627{
2629 HDESK Desktop;
2630
2634 UserMode,
2635 NULL,
2636 dwDesiredAccess,
2637 NULL,
2638 (HANDLE*)&Desktop);
2639
2640 if (!NT_SUCCESS(Status))
2641 {
2642 ERR("Failed to open desktop\n");
2644 return NULL;
2645 }
2646
2647 TRACE("Opened desktop %S with handle 0x%p\n", ObjectAttributes->ObjectName->Buffer, Desktop);
2648
2649 return Desktop;
2650}
2651
2653 BOOL fInherit,
2654 ACCESS_MASK dwDesiredAccess)
2655{
2659 HDESK hdesk = NULL;
2660
2661 if (!gpdeskInputDesktop)
2662 {
2663 return NULL;
2664 }
2665
2666 if (pti->ppi->prpwinsta != InputWindowStation)
2667 {
2668 ERR("Tried to open input desktop from non interactive winsta!\n");
2670 return NULL;
2671 }
2672
2673 if (fInherit) HandleAttributes = OBJ_INHERIT;
2674
2675 /* Create a new handle to the object */
2679 NULL,
2680 dwDesiredAccess,
2682 UserMode,
2683 (PHANDLE)&hdesk);
2684
2685 if (!NT_SUCCESS(Status))
2686 {
2687 ERR("Failed to open input desktop object\n");
2689 }
2690
2691 return hdesk;
2692}
2693
2694/*
2695 * NtUserOpenInputDesktop
2696 *
2697 * Opens the input (interactive) desktop.
2698 *
2699 * Parameters
2700 * dwFlags
2701 * Interaction flags.
2702 *
2703 * fInherit
2704 * Inheritance option.
2705 *
2706 * dwDesiredAccess
2707 * Requested type of access.
2708 *
2709 * Return Value
2710 * Handle to the input desktop or zero on failure.
2711 *
2712 * Status
2713 * @implemented
2714 */
2715
2716HDESK APIENTRY
2718 DWORD dwFlags,
2719 BOOL fInherit,
2720 ACCESS_MASK dwDesiredAccess)
2721{
2722 HDESK hdesk;
2723
2725 TRACE("Enter NtUserOpenInputDesktop gpdeskInputDesktop 0x%p\n", gpdeskInputDesktop);
2726
2727 hdesk = UserOpenInputDesktop(dwFlags, fInherit, dwDesiredAccess);
2728
2729 TRACE("NtUserOpenInputDesktop returning 0x%p\n", hdesk);
2730 UserLeave();
2731 return hdesk;
2732}
2733
2734/*
2735 * NtUserCloseDesktop
2736 *
2737 * Closes a desktop handle.
2738 *
2739 * Parameters
2740 * hDesktop
2741 * Handle to the desktop.
2742 *
2743 * Return Value
2744 * Status
2745 *
2746 * Remarks
2747 * The desktop handle can be created with NtUserCreateDesktop or
2748 * NtUserOpenDesktop. This function will fail if any thread in the calling
2749 * process is using the specified desktop handle or if the handle refers
2750 * to the initial desktop of the calling process.
2751 *
2752 * Status
2753 * @implemented
2754 */
2755
2757NtUserCloseDesktop(HDESK hDesktop)
2758{
2759 PDESKTOP pdesk;
2761 BOOL Ret = FALSE;
2762
2763 TRACE("NtUserCloseDesktop(0x%p) called\n", hDesktop);
2765
2766 if (hDesktop == gptiCurrent->hdesk || hDesktop == gptiCurrent->ppi->hdeskStartup)
2767 {
2768 ERR("Attempted to close thread desktop\n");
2770 goto Exit; // Return FALSE
2771 }
2772
2773 Status = IntValidateDesktopHandle(hDesktop, UserMode, 0, &pdesk);
2774 if (!NT_SUCCESS(Status))
2775 {
2776 ERR("Validation of desktop handle 0x%p failed\n", hDesktop);
2777 goto Exit; // Return FALSE
2778 }
2779
2780 ObDereferenceObject(pdesk);
2781
2782 Status = ObCloseHandle(hDesktop, UserMode);
2783 if (!NT_SUCCESS(Status))
2784 {
2785 ERR("Failed to close desktop handle 0x%p\n", hDesktop);
2787 goto Exit; // Return FALSE
2788 }
2789
2790 Ret = TRUE;
2791
2792Exit:
2793 TRACE("Leave NtUserCloseDesktop, ret=%i\n", Ret);
2794 UserLeave();
2795 return Ret;
2796}
2797
2798/*
2799 * NtUserPaintDesktop
2800 *
2801 * The NtUserPaintDesktop function fills the clipping region in the
2802 * specified device context with the desktop pattern or wallpaper. The
2803 * function is provided primarily for shell desktops.
2804 *
2805 * Parameters
2806 * hDC
2807 * Handle to the device context.
2808 *
2809 * Status
2810 * @implemented
2811 */
2812
2815{
2816 BOOL Ret;
2817
2819 TRACE("Enter NtUserPaintDesktop\n");
2820
2821 Ret = IntPaintDesktop(hDC);
2822
2823 TRACE("Leave NtUserPaintDesktop, ret=%i\n", Ret);
2824 UserLeave();
2825 return Ret;
2826}
2827
2828/*
2829 * NtUserResolveDesktop
2830 *
2831 * The NtUserResolveDesktop function attempts to retrieve valid handles to
2832 * a desktop and a window station suitable for the specified process.
2833 * The specified desktop path string is used only as a hint for the resolution.
2834 *
2835 * See the description of IntResolveDesktop for more details.
2836 *
2837 * Parameters
2838 * ProcessHandle
2839 * Handle to a user process.
2840 *
2841 * DesktopPath
2842 * The desktop path string used as a hint for desktop resolution.
2843 *
2844 * bInherit
2845 * Whether or not the returned handles are inheritable.
2846 *
2847 * phWinSta
2848 * Pointer to a window station handle.
2849 *
2850 * Return Value
2851 * Handle to the desktop (direct return value) and
2852 * handle to the associated window station (by pointer).
2853 * NULL in case of failure.
2854 *
2855 * Remarks
2856 * Callable by CSRSS only.
2857 *
2858 * Status
2859 * @implemented
2860 */
2861
2862HDESK
2863NTAPI
2866 IN PUNICODE_STRING DesktopPath,
2867 IN BOOL bInherit,
2868 OUT HWINSTA* phWinSta)
2869{
2872 HWINSTA hWinSta = NULL;
2873 HDESK hDesktop = NULL;
2874 UNICODE_STRING CapturedDesktopPath;
2875
2876 /* Allow only the Console Server to perform this operation (via CSRSS) */
2878 return NULL;
2879
2880 /* Get the process object the user handle was referencing */
2884 UserMode,
2885 (PVOID*)&Process,
2886 NULL);
2887 if (!NT_SUCCESS(Status))
2888 return NULL;
2889
2891
2892 _SEH2_TRY
2893 {
2894 /* Probe the handle pointer */
2895 // ProbeForWriteHandle
2896 ProbeForWrite(phWinSta, sizeof(HWINSTA), sizeof(HWINSTA));
2897 }
2899 {
2901 _SEH2_YIELD(goto Quit);
2902 }
2903 _SEH2_END;
2904
2905 /* Capture the user desktop path string */
2906 Status = ProbeAndCaptureUnicodeString(&CapturedDesktopPath,
2907 UserMode,
2908 DesktopPath);
2909 if (!NT_SUCCESS(Status))
2910 goto Quit;
2911
2912 /* Call the internal function */
2914 &CapturedDesktopPath,
2915 bInherit,
2916 &hWinSta,
2917 &hDesktop);
2918 if (!NT_SUCCESS(Status))
2919 {
2920 ERR("IntResolveDesktop failed, Status 0x%08lx\n", Status);
2921 hWinSta = NULL;
2922 hDesktop = NULL;
2923 }
2924
2925 _SEH2_TRY
2926 {
2927 /* Return the window station handle */
2928 *phWinSta = hWinSta;
2929 }
2931 {
2933
2934 /* We failed, close the opened desktop and window station */
2935 if (hDesktop) ObCloseHandle(hDesktop, UserMode);
2936 hDesktop = NULL;
2937 if (hWinSta) ObCloseHandle(hWinSta, UserMode);
2938 }
2939 _SEH2_END;
2940
2941 /* Free the captured string */
2942 ReleaseCapturedUnicodeString(&CapturedDesktopPath, UserMode);
2943
2944Quit:
2945 UserLeave();
2946
2947 /* Dereference the process object */
2949
2950 /* Return the desktop handle */
2951 return hDesktop;
2952}
2953
2954/*
2955 * NtUserSwitchDesktop
2956 *
2957 * Sets the current input (interactive) desktop.
2958 *
2959 * Parameters
2960 * hDesktop
2961 * Handle to desktop.
2962 *
2963 * Return Value
2964 * Status
2965 *
2966 * Status
2967 * @unimplemented
2968 */
2969
2972{
2973 PDESKTOP pdesk;
2975 BOOL bRedrawDesktop;
2976 BOOL Ret = FALSE;
2977
2979 TRACE("Enter NtUserSwitchDesktop(0x%p)\n", hdesk);
2980
2981 Status = IntValidateDesktopHandle(hdesk, UserMode, 0, &pdesk);
2982 if (!NT_SUCCESS(Status))
2983 {
2984 ERR("Validation of desktop handle 0x%p failed\n", hdesk);
2985 goto Exit; // Return FALSE
2986 }
2987
2988 if (PsGetCurrentProcessSessionId() != pdesk->rpwinstaParent->dwSessionId)
2989 {
2990 ObDereferenceObject(pdesk);
2991 ERR("NtUserSwitchDesktop called for a desktop of a different session\n");
2992 goto Exit; // Return FALSE
2993 }
2994
2995 if (pdesk == gpdeskInputDesktop)
2996 {
2997 ObDereferenceObject(pdesk);
2998 WARN("NtUserSwitchDesktop called for active desktop\n");
2999 Ret = TRUE;
3000 goto Exit;
3001 }
3002
3003 /*
3004 * Don't allow applications switch the desktop if it's locked, unless the caller
3005 * is the logon application itself
3006 */
3007 if ((pdesk->rpwinstaParent->Flags & WSS_LOCKED) &&
3009 {
3010 ObDereferenceObject(pdesk);
3011 ERR("Switching desktop 0x%p denied because the window station is locked!\n", hdesk);
3012 goto Exit; // Return FALSE
3013 }
3014
3015 if (pdesk->rpwinstaParent != InputWindowStation)
3016 {
3017 ObDereferenceObject(pdesk);
3018 ERR("Switching desktop 0x%p denied because desktop doesn't belong to the interactive winsta!\n", hdesk);
3019 goto Exit; // Return FALSE
3020 }
3021
3022 /* FIXME: Fail if the process is associated with a secured
3023 desktop such as Winlogon or Screen-Saver */
3024 /* FIXME: Connect to input device */
3025
3026 TRACE("Switching from desktop 0x%p to 0x%p\n", gpdeskInputDesktop, pdesk);
3027
3028 bRedrawDesktop = FALSE;
3029
3030 /* The first time SwitchDesktop is called, gpdeskInputDesktop is NULL */
3031 if (gpdeskInputDesktop != NULL)
3032 {
3034 bRedrawDesktop = TRUE;
3035
3036 /* Hide the previous desktop window */
3038 }
3039
3040 /* Set the active desktop in the desktop's window station. */
3042
3043 /* Set the global state. */
3044 gpdeskInputDesktop = pdesk;
3045
3046 /* Show the new desktop window */
3048
3049 TRACE("SwitchDesktop gpdeskInputDesktop 0x%p\n", gpdeskInputDesktop);
3050 ObDereferenceObject(pdesk);
3051
3052 Ret = TRUE;
3053
3054Exit:
3055 TRACE("Leave NtUserSwitchDesktop, ret=%i\n", Ret);
3056 UserLeave();
3057 return Ret;
3058}
3059
3060/*
3061 * NtUserGetThreadDesktop
3062 *
3063 * Status
3064 * @implemented
3065 */
3066
3067HDESK APIENTRY
3069{
3070 HDESK hDesk;
3072 PTHREADINFO pti;
3074 PDESKTOP DesktopObject;
3076
3078 TRACE("Enter NtUserGetThreadDesktop\n");
3079
3080 if (!dwThreadId)
3081 {
3083 hDesk = NULL;
3084 goto Quit;
3085 }
3086
3087 /* Validate the Win32 thread and retrieve its information */
3089 if (pti)
3090 {
3091 /* Get the desktop handle of the thread */
3092 hDesk = pti->hdesk;
3093 Process = pti->ppi->peProcess;
3094 }
3095 else if (hConsoleDesktop)
3096 {
3097 /*
3098 * The thread may belong to a console, so attempt to use the provided
3099 * console desktop handle as a fallback. Otherwise this means that the
3100 * thread is either not Win32 or invalid.
3101 */
3102 hDesk = hConsoleDesktop;
3104 }
3105 else
3106 {
3108 hDesk = NULL;
3109 goto Quit;
3110 }
3111
3112 if (!hDesk)
3113 {
3114 ERR("Desktop information of thread 0x%x broken!?\n", dwThreadId);
3115 goto Quit;
3116 }
3117
3119 {
3120 /*
3121 * Just return the handle, since we queried the desktop handle
3122 * of a thread running in the same context.
3123 */
3124 goto Quit;
3125 }
3126
3127 /*
3128 * We could just use the cached rpdesk instead of looking up the handle,
3129 * but it may actually be safer to validate the desktop and get a temporary
3130 * reference to it so that it does not disappear under us (e.g. when the
3131 * desktop is being destroyed) during the operation.
3132 */
3133 /*
3134 * Switch into the context of the thread we are trying to get
3135 * the desktop from, so we can use the handle.
3136 */
3137 KeAttachProcess(&Process->Pcb);
3139 0,
3141 UserMode,
3142 (PVOID*)&DesktopObject,
3145
3146 if (NT_SUCCESS(Status))
3147 {
3148 /*
3149 * Lookup our handle table if we can find a handle to the desktop object.
3150 * If not, create one.
3151 * QUESTION: Do we really need to create a handle in case it doesn't exist??
3152 */
3153 hDesk = IntGetDesktopObjectHandle(DesktopObject);
3154
3155 /* All done, we got a valid handle to the desktop */
3156 ObDereferenceObject(DesktopObject);
3157 }
3158 else
3159 {
3160 /* The handle could not be found, there is nothing to get... */
3161 hDesk = NULL;
3162 }
3163
3164 if (!hDesk)
3165 {
3166 ERR("Could not retrieve or access desktop for thread 0x%x\n", dwThreadId);
3168 }
3169
3170Quit:
3171 TRACE("Leave NtUserGetThreadDesktop, hDesk = 0x%p\n", hDesk);
3172 UserLeave();
3173 return hDesk;
3174}
3175
3176static NTSTATUS
3178{
3179 PPROCESSINFO ppi;
3180 PW32HEAP_USER_MAPPING HeapMapping, *PrevLink;
3182
3183 TRACE("IntUnmapDesktopView called for desktop object %p\n", pdesk);
3184
3186
3187 /*
3188 * Unmap if we're the last thread using the desktop.
3189 * Start the search at the next mapping: skip the first entry
3190 * as it must be the global user heap mapping.
3191 */
3192 PrevLink = &ppi->HeapMappings.Next;
3193 HeapMapping = *PrevLink;
3194 while (HeapMapping != NULL)
3195 {
3196 if (HeapMapping->KernelMapping == (PVOID)pdesk->pheapDesktop)
3197 {
3198 if (--HeapMapping->Count == 0)
3199 {
3200 *PrevLink = HeapMapping->Next;
3201
3202 TRACE("ppi 0x%p unmapped heap of desktop 0x%p\n", ppi, pdesk);
3204 HeapMapping->UserMapping);
3205
3206 ObDereferenceObject(pdesk);
3207
3208 UserHeapFree(HeapMapping);
3209 break;
3210 }
3211 }
3212
3213 PrevLink = &HeapMapping->Next;
3214 HeapMapping = HeapMapping->Next;
3215 }
3216
3217 return Status;
3218}
3219
3220static NTSTATUS
3222{
3223 PPROCESSINFO ppi;
3224 PW32HEAP_USER_MAPPING HeapMapping, *PrevLink;
3225 PVOID UserBase = NULL;
3226 SIZE_T ViewSize = 0;
3229
3230 TRACE("IntMapDesktopView called for desktop object 0x%p\n", pdesk);
3231
3233
3234 /*
3235 * Find out if another thread already mapped the desktop heap.
3236 * Start the search at the next mapping: skip the first entry
3237 * as it must be the global user heap mapping.
3238 */
3239 PrevLink = &ppi->HeapMappings.Next;
3240 HeapMapping = *PrevLink;
3241 while (HeapMapping != NULL)
3242 {
3243 if (HeapMapping->KernelMapping == (PVOID)pdesk->pheapDesktop)
3244 {
3245 HeapMapping->Count++;
3246 return STATUS_SUCCESS;
3247 }
3248
3249 PrevLink = &HeapMapping->Next;
3250 HeapMapping = HeapMapping->Next;
3251 }
3252
3253 /* We're the first, map the heap */
3254 Offset.QuadPart = 0;
3255 Status = MmMapViewOfSection(pdesk->hsectionDesktop,
3257 &UserBase,
3258 0,
3259 0,
3260 &Offset,
3261 &ViewSize,
3262 ViewUnmap,
3265 if (!NT_SUCCESS(Status))
3266 {
3267 ERR("Failed to map desktop\n");
3268 return Status;
3269 }
3270
3271 TRACE("ppi 0x%p mapped heap of desktop 0x%p\n", ppi, pdesk);
3272
3273 /* Add the mapping */
3274 HeapMapping = UserHeapAlloc(sizeof(*HeapMapping));
3275 if (HeapMapping == NULL)
3276 {
3278 ERR("UserHeapAlloc() failed!\n");
3279 return STATUS_NO_MEMORY;
3280 }
3281
3282 HeapMapping->Next = NULL;
3283 HeapMapping->KernelMapping = (PVOID)pdesk->pheapDesktop;
3284 HeapMapping->UserMapping = UserBase;
3285 HeapMapping->Limit = ViewSize;
3286 HeapMapping->Count = 1;
3287 *PrevLink = HeapMapping;
3288
3289 ObReferenceObject(pdesk);
3290
3291 return STATUS_SUCCESS;
3292}
3293
3294BOOL
3296 IN BOOL FreeOnFailure)
3297{
3298 PDESKTOP pdesk = NULL, pdeskOld;
3299 PTHREADINFO pti;
3301 PCLIENTTHREADINFO pctiOld, pctiNew = NULL;
3302 PCLIENTINFO pci;
3303
3305
3306 TRACE("IntSetThreadDesktop hDesktop:0x%p, FOF:%i\n",hDesktop, FreeOnFailure);
3307
3309 pci = pti->pClientInfo;
3310
3311 /* If the caller gave us a desktop, ensure it is valid */
3312 if (hDesktop != NULL)
3313 {
3314 /* Validate the new desktop. */
3315 Status = IntValidateDesktopHandle(hDesktop, UserMode, 0, &pdesk);
3316 if (!NT_SUCCESS(Status))
3317 {
3318 ERR("Validation of desktop handle 0x%p failed\n", hDesktop);
3319 return FALSE;
3320 }
3321
3322 if (pti->rpdesk == pdesk)
3323 {
3324 /* Nothing to do */
3325 ObDereferenceObject(pdesk);
3326 return TRUE;
3327 }
3328 }
3329
3330 /* Make sure that we don't own any window in the current desktop */
3331 if (!IsListEmpty(&pti->WindowListHead))
3332 {
3333 if (pdesk)
3334 ObDereferenceObject(pdesk);
3335 ERR("Attempted to change thread desktop although the thread has windows!\n");
3337 return FALSE;
3338 }
3339
3340 /* Desktop is being re-set so clear out foreground. */
3341 if (pti->rpdesk != pdesk && pti->MessageQueue == gpqForeground)
3342 {
3343 // Like above, there shouldn't be any windows, hooks or anything active on this threads desktop!
3345 }
3346
3347 /* Before doing the switch, map the new desktop heap and allocate the new pcti */
3348 if (pdesk != NULL)
3349 {
3350 Status = IntMapDesktopView(pdesk);
3351 if (!NT_SUCCESS(Status))
3352 {
3353 ERR("Failed to map desktop heap!\n");
3354 ObDereferenceObject(pdesk);
3356 return FALSE;
3357 }
3358
3359 pctiNew = DesktopHeapAlloc(pdesk, sizeof(CLIENTTHREADINFO));
3360 if (pctiNew == NULL)
3361 {
3362 ERR("Failed to allocate new pcti\n");
3363 IntUnmapDesktopView(pdesk);
3364 ObDereferenceObject(pdesk);
3366 return FALSE;
3367 }
3368 }
3369
3370 /*
3371 * Processes, in particular Winlogon.exe, that manage window stations
3372 * (especially the interactive WinSta0 window station) and desktops,
3373 * may not be able to connect at startup to a window station and have
3374 * an associated desktop as well, if none exists on the system already.
3375 * Because creating a new window station does not affect the window station
3376 * associated to the process, and because neither by associating a window
3377 * station to the process nor creating a new desktop on it does associate
3378 * a startup desktop to that process, the process has to actually assigns
3379 * one of its threads to a desktop so that it gets automatically an assigned
3380 * startup desktop.
3381 *
3382 * This is what actually happens for Winlogon.exe, which is started without
3383 * any window station and desktop. By creating the first (and therefore
3384 * interactive) WinSta0 window station, then assigning WinSta0 to itself
3385 * and creating the Default desktop on it, and then assigning this desktop
3386 * to its main thread, Winlogon.exe basically does the similar steps that
3387 * would have been done automatically at its startup if there were already
3388 * an existing WinSta0 window station and Default desktop.
3389 *
3390 * Of course all this must not be done if we are a SYSTEM or CSRSS thread.
3391 */
3392 // if (pti->ppi->peProcess != gpepCSRSS)
3393 if (!(pti->TIF_flags & (TIF_SYSTEMTHREAD | TIF_CSRSSTHREAD)) &&
3394 pti->ppi->rpdeskStartup == NULL && hDesktop != NULL)
3395 {
3396 ERR("The process 0x%p '%s' didn't have an assigned startup desktop before, assigning it now!\n",
3397 pti->ppi->peProcess, pti->ppi->peProcess->ImageFileName);
3398
3399 pti->ppi->hdeskStartup = hDesktop;
3400 pti->ppi->rpdeskStartup = pdesk;
3401 }
3402
3403 /* free all classes or move them to the shared heap */
3404 if (pti->rpdesk != NULL)
3405 {
3406 if (!IntCheckProcessDesktopClasses(pti->rpdesk, FreeOnFailure))
3407 {
3408 ERR("Failed to move process classes to shared heap!\n");
3409 if (pdesk)
3410 {
3411 DesktopHeapFree(pdesk, pctiNew);
3412 IntUnmapDesktopView(pdesk);
3413 ObDereferenceObject(pdesk);
3414 }
3415 return FALSE;
3416 }
3417 }
3418
3419 pdeskOld = pti->rpdesk;
3420 if (pti->pcti != &pti->cti)
3421 pctiOld = pti->pcti;
3422 else
3423 pctiOld = NULL;
3424
3425 /* do the switch */
3426 if (pdesk != NULL)
3427 {
3428 pti->rpdesk = pdesk;
3429 pti->hdesk = hDesktop;
3430 pti->pDeskInfo = pti->rpdesk->pDeskInfo;
3431 pti->pcti = pctiNew;
3432
3434 pci->pDeskInfo = (PVOID)((ULONG_PTR)pti->pDeskInfo - pci->ulClientDelta);
3435 pci->pClientThreadInfo = (PVOID)((ULONG_PTR)pti->pcti - pci->ulClientDelta);
3436
3437 /* initialize the new pcti */
3438 if (pctiOld != NULL)
3439 {
3440 RtlCopyMemory(pctiNew, pctiOld, sizeof(CLIENTTHREADINFO));
3441 }
3442 else
3443 {
3444 RtlZeroMemory(pctiNew, sizeof(CLIENTTHREADINFO));
3445 pci->fsHooks = pti->fsHooks;
3446 pci->dwTIFlags = pti->TIF_flags;
3447 }
3448 }
3449 else
3450 {
3451 pti->rpdesk = NULL;
3452 pti->hdesk = NULL;
3453 pti->pDeskInfo = NULL;
3454 pti->pcti = &pti->cti; // Always point inside so there will be no crash when posting or sending msg's!
3455 pci->ulClientDelta = 0;
3456 pci->pDeskInfo = NULL;
3457 pci->pClientThreadInfo = NULL;
3458 }
3459
3460 /* clean up the old desktop */
3461 if (pdeskOld != NULL)
3462 {
3463 RemoveEntryList(&pti->PtiLink);
3464 if (pctiOld) DesktopHeapFree(pdeskOld, pctiOld);
3465 IntUnmapDesktopView(pdeskOld);
3466 ObDereferenceObject(pdeskOld);
3467 }
3468
3469 if (pdesk)
3470 {
3471 InsertTailList(&pdesk->PtiList, &pti->PtiLink);
3472 }
3473
3474 TRACE("IntSetThreadDesktop: pti 0x%p ppi 0x%p switched from object 0x%p to 0x%p\n", pti, pti->ppi, pdeskOld, pdesk);
3475
3476 return TRUE;
3477}
3478
3479/*
3480 * NtUserSetThreadDesktop
3481 *
3482 * Status
3483 * @implemented
3484 */
3485
3488{
3489 BOOL ret = FALSE;
3490
3492
3493 // FIXME: IntSetThreadDesktop validates the desktop handle, it should happen
3494 // here too and set the NT error level. Q. Is it necessary to have the validation
3495 // in IntSetThreadDesktop? Is it needed there too?
3496 if (hDesktop || (!hDesktop && PsGetCurrentProcess() == gpepCSRSS))
3497 ret = IntSetThreadDesktop(hDesktop, FALSE);
3498
3499 UserLeave();
3500
3501 return ret;
3502}
3503
3504/* EOF */
static HDC hDC
Definition: 3dtext.c:33
NTSTATUS NTAPI MmUnmapViewInSessionSpace(IN PVOID MappedBase)
Definition: section.c:2724
NTSTATUS NTAPI MmUnmapViewOfSection(IN PEPROCESS Process, IN PVOID BaseAddress)
Definition: section.c:2752
#define CODE_SEG(...)
unsigned char BOOLEAN
#define OBJ_NAME_PATH_SEPARATOR
Definition: arcname_tests.c:25
HWND hWnd
Definition: settings.c:17
LONG NTSTATUS
Definition: precomp.h:26
#define WARN(fmt,...)
Definition: precomp.h:61
#define ERR(fmt,...)
Definition: precomp.h:57
#define UlongToHandle(ul)
Definition: basetsd.h:91
#define HandleToULong(h)
Definition: basetsd.h:89
#define DBG_DEFAULT_CHANNEL(ch)
Definition: debug.h:106
PVOID NTAPI RtlAllocateHeap(IN PVOID HeapHandle, IN ULONG Flags, IN SIZE_T Size)
Definition: heap.c:616
_Inout_ PFCB _Inout_ PUNICODE_STRING RemainingName
Definition: cdprocs.h:802
Definition: list.h:37
WPARAM wParam
Definition: combotst.c:138
LPARAM lParam
Definition: combotst.c:139
struct @1765 Msg[]
IN PUNICODE_STRING IN POBJECT_ATTRIBUTES ObjectAttributes
Definition: conport.c:36
PEPROCESS gpepCSRSS
Definition: csr.c:15
#define STATUS_NO_MEMORY
Definition: d3dkmdt.h:51
FORCEINLINE VOID DC_UnlockDc(PDC pdc)
Definition: dc.h:238
COLORREF FASTCALL IntGdiSetTextColor(HDC hDC, COLORREF color)
Definition: dcutil.c:172
@ DCTYPE_DIRECT
Definition: dc.h:41
UINT FASTCALL IntGdiSetTextAlign(HDC hDC, UINT Mode)
Definition: dcutil.c:145
INT FASTCALL IntGdiSetBkMode(HDC hDC, INT backgroundMode)
Definition: dcutil.c:124
HDC FASTCALL IntGdiCreateDisplayDC(HDEV hDev, ULONG DcType, BOOL EmptyDC)
Definition: dclife.c:1063
FORCEINLINE PDC DC_LockDc(HDC hdc)
Definition: dc.h:220
#define ERROR_NOT_ENOUGH_MEMORY
Definition: dderror.h:7
#define ERROR_BUSY
Definition: dderror.h:12
#define ERROR_INVALID_FUNCTION
Definition: dderror.h:6
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:33
#define ARRAYSIZE(array)
Definition: filtermapper.c:47
NTSTATUS NTAPI RtlGetVersion(IN OUT PRTL_OSVERSIONINFOW lpVersionInformation)
Definition: version.c:182
#define APIENTRY
Definition: api.h:79
#define wcschr
Definition: compat.h:17
#define ERROR_INVALID_PARAMETER
Definition: compat.h:101
#define PAGE_READONLY
Definition: compat.h:138
#define wcsrchr
Definition: compat.h:16
#define ERROR_ACCESS_DENIED
Definition: compat.h:97
#define HEAP_ZERO_MEMORY
Definition: compat.h:134
#define lstrlenW
Definition: compat.h:750
static const WCHAR Message[]
Definition: register.c:74
#define RGB(r, g, b)
Definition: precomp.h:71
#define GetBValue(quad)
Definition: precomp.h:75
#define GetGValue(quad)
Definition: precomp.h:74
#define GetRValue(quad)
Definition: precomp.h:73
return ret
Definition: mutex.c:146
#define L(x)
Definition: resources.c:13
#define InterlockedExchangePointer(Target, Value)
Definition: dshow.h:45
#define RemoveEntryList(Entry)
Definition: env_spec_w32.h:986
#define InsertTailList(ListHead, Entry)
UNICODE_STRING * PUNICODE_STRING
Definition: env_spec_w32.h:373
#define ExAllocatePoolWithTag(hernya, size, tag)
Definition: env_spec_w32.h:350
#define IsListEmpty(ListHead)
Definition: env_spec_w32.h:954
#define KeInitializeEvent(pEvt, foo, foo2)
Definition: env_spec_w32.h:477
#define KeSetEvent(pEvt, foo, foo2)
Definition: env_spec_w32.h:476
#define NonPagedPool
Definition: env_spec_w32.h:307
#define InitializeListHead(ListHead)
Definition: env_spec_w32.h:944
#define PagedPool
Definition: env_spec_w32.h:308
#define ERROR(name)
Definition: error_private.h:53
VOID NTAPI ProbeForWrite(IN PVOID Address, IN SIZE_T Length, IN ULONG Alignment)
Definition: exintrin.c:143
DWORD dwThreadId
Definition: fdebug.c:31
PsGetCurrentThreadId
Definition: CrNtStubs.h:8
unsigned int BOOL
Definition: ntddk_ex.h:94
unsigned long DWORD
Definition: ntddk_ex.h:95
PUSER_MESSAGE_QUEUE gpqForeground
Definition: focus.c:13
PTHREADINFO ptiLastInput
Definition: focus.c:18
PUSER_MESSAGE_QUEUE gpqForegroundPrev
Definition: focus.c:14
BOOL APIENTRY GreExtTextOutW(_In_ HDC hDC, _In_ INT XStart, _In_ INT YStart, _In_ UINT fuOptions, _In_opt_ PRECTL lprc, _In_reads_opt_(Count) PCWCH String, _In_ INT Count, _In_opt_ const INT *Dx, _In_ DWORD dwCodePage)
Definition: freetype.c:7504
_Must_inspect_result_ _In_ PLARGE_INTEGER _In_ PLARGE_INTEGER _In_ ULONG _In_ PFILE_OBJECT _In_ PVOID Process
Definition: fsrtlfuncs.h:223
Status
Definition: gdiplustypes.h:25
GLint GLint GLint GLint GLint x
Definition: gl.h:1548
GLint GLint GLint GLint GLint GLint y
Definition: gl.h:1548
GLdouble n
Definition: glext.h:7729
GLbitfield flags
Definition: glext.h:7161
GLenum GLsizei len
Definition: glext.h:6722
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
#define ISITHOOKED(HookId)
Definition: hook.h:6
const char cursor[]
Definition: icontest.c:13
PSERVERINFO gpsi
Definition: imm.c:18
_Check_return_ _CRTIMP int __cdecl _scwprintf(_In_z_ _Printf_format_string_ const wchar_t *_Format,...)
_CRTIMP size_t __cdecl wcslen(_In_z_ const wchar_t *_Str)
#define PROCESS_QUERY_INFORMATION
Definition: pstypes.h:167
#define TIF_CSRSSTHREAD
Definition: ntuser.h:266
#define FNID_DESTROY
Definition: ntuser.h:898
#define FNID_DESKTOP
Definition: ntuser.h:862
#define UserHMGetHandle(obj)
Definition: ntuser.h:230
#define CURSORF_CURRENT
Definition: ntuser.h:1207
struct _DESKTOPINFO DESKTOPINFO
#define FNID_MESSAGEWND
Definition: ntuser.h:864
#define TIF_SYSTEMTHREAD
Definition: ntuser.h:265
#define NB_HOOKS
Definition: ntuser.h:127
#define TIF_DISABLEHOOKS
Definition: ntuser.h:291
#define OBJ_KERNEL_HANDLE
Definition: winternl.h:231
#define OBJ_OPENIF
Definition: winternl.h:229
#define OBJ_CASE_INSENSITIVE
Definition: winternl.h:228
#define OBJ_INHERIT
Definition: winternl.h:225
#define EXCEPTION_EXECUTE_HANDLER
Definition: excpt.h:90
NTSYSAPI NTSTATUS WINAPI RtlQueryRegistryValues(ULONG, PCWSTR, PRTL_QUERY_REGISTRY_TABLE, PVOID, PVOID)
#define NOTHING
Definition: input_list.c:10
#define NtCurrentTeb
if(dx< 0)
Definition: linetemp.h:194
_In_ BOOL _In_ HANDLE hProcess
Definition: mapping.h:71
LONG_PTR LPARAM
Definition: minwindef.h:175
LONG_PTR LRESULT
Definition: minwindef.h:176
UINT_PTR WPARAM
Definition: minwindef.h:174
#define ASSERT(a)
Definition: mode.c:44
#define ExFreePoolWithTag(_P, _T)
Definition: module.h:1109
#define DESKTOP_ALL_ACCESS
Definition: precomp.h:22
static HBITMAP
Definition: button.c:44
static HDC
Definition: imagelist.c:88
static LPCSTR lpstr
Definition: font.c:51
static DWORD *static HFONT(WINAPI *pCreateFontIndirectExA)(const ENUMLOGFONTEXDVA *)
ObjectType
Definition: metafile.c:81
#define InitializeObjectAttributes(p, n, a, r, s)
Definition: reg.c:106
#define min(a, b)
Definition: monoChain.cc:55
PCURICON_OBJECT FASTCALL UserSetCursor(PCURICON_OBJECT NewCursor, BOOL ForceChange)
Definition: msgqueue.c:93
#define IntReferenceMessageQueue(MsgQueue)
Definition: msgqueue.h:217
#define IntDereferenceMessageQueue(MsgQueue)
Definition: msgqueue.h:220
struct _USER_MESSAGE_QUEUE * PUSER_MESSAGE_QUEUE
unsigned int UINT
Definition: ndis.h:50
#define KernelMode
Definition: asm.h:38
#define UserMode
Definition: asm.h:39
_In_ HANDLE ProcessHandle
Definition: mmfuncs.h:403
_In_ HANDLE _Outptr_result_bytebuffer_ ViewSize PVOID _In_ ULONG_PTR _In_ SIZE_T _Inout_opt_ PLARGE_INTEGER _Inout_ PSIZE_T ViewSize
Definition: mmfuncs.h:408
#define SEC_NO_CHANGE
Definition: mmtypes.h:95
_In_ HANDLE _In_opt_ HANDLE _Out_opt_ PHANDLE _In_ ACCESS_MASK _In_ ULONG HandleAttributes
Definition: obfuncs.h:433
_In_ LPWSTR _In_ DWORD _In_ DWORD _In_ DWORD dwFlags
Definition: netsh.h:141
#define _In_
Definition: no_sal2.h:158
ULONG ACCESS_MASK
Definition: nt_native.h:40
#define PAGE_READWRITE
Definition: nt_native.h:1307
NTSYSAPI VOID NTAPI RtlInitUnicodeString(PUNICODE_STRING DestinationString, PCWSTR SourceString)
NTSYSAPI BOOLEAN NTAPI RtlEqualUnicodeString(PUNICODE_STRING String1, PUNICODE_STRING String2, BOOLEAN CaseInSensitive)
#define FASTCALL
Definition: nt_native.h:50
#define RTL_REGISTRY_WINDOWS_NT
Definition: nt_native.h:164
#define RTL_QUERY_REGISTRY_DIRECT
Definition: nt_native.h:144
@ ViewUnmap
Definition: nt_native.h:1282
#define MEM_RELEASE
Definition: nt_native.h:1319
#define REG_NONE
Definition: nt_native.h:1495
#define MEM_COMMIT
Definition: nt_native.h:1316
#define HEAP_NO_SERIALIZE
Definition: nt_native.h:1695
#define MAXIMUM_ALLOWED
Definition: nt_native.h:83
#define UNICODE_NULL
_In_ ULONG _In_ ULONG Offset
Definition: ntddpcm.h:101
@ SynchronizationEvent
__kernel_entry W32KAPI HDC APIENTRY NtGdiCreateCompatibleDC(_In_opt_ HDC hdc)
__kernel_entry W32KAPI BOOL APIENTRY NtGdiBitBlt(_In_ HDC hdcDst, _In_ INT x, _In_ INT y, _In_ INT cx, _In_ INT cy, _In_opt_ HDC hdcSrc, _In_ INT xSrc, _In_ INT ySrc, _In_ DWORD rop4, _In_ DWORD crBackColor, _In_ FLONG fl)
__kernel_entry W32KAPI HBRUSH APIENTRY NtGdiSelectBrush(_In_ HDC hdc, _In_ HBRUSH hbrush)
__kernel_entry W32KAPI BOOL APIENTRY NtGdiStretchBlt(_In_ HDC hdcDst, _In_ INT xDst, _In_ INT yDst, _In_ INT cxDst, _In_ INT cyDst, _In_opt_ HDC hdcSrc, _In_ INT xSrc, _In_ INT ySrc, _In_ INT cxSrc, _In_ INT cySrc, _In_ DWORD dwRop, _In_ DWORD dwBackColor)
__kernel_entry W32KAPI HBITMAP APIENTRY NtGdiSelectBitmap(_In_ HDC hdc, _In_ HBITMAP hbm)
__kernel_entry W32KAPI BOOL APIENTRY NtGdiPatBlt(_In_ HDC hdcDest, _In_ INT x, _In_ INT y, _In_ INT cx, _In_ INT cy, _In_ DWORD dwRop)
Definition: bitblt.c:990
__kernel_entry W32KAPI BOOL APIENTRY NtGdiDeleteObjectApp(_In_ HANDLE hobj)
__kernel_entry W32KAPI HFONT APIENTRY NtGdiSelectFont(_In_ HDC hdc, _In_ HFONT hf)
Definition: dcobjs.c:597
PVOID NTAPI PsGetProcessWin32Process(PEPROCESS Process)
Definition: process.c:1193
POBJECT_TYPE PsProcessType
Definition: process.c:20
PVOID NTAPI PsGetCurrentProcessWin32Process(VOID)
Definition: process.c:1183
HANDLE NTAPI PsGetCurrentProcessId(VOID)
Definition: process.c:1123
ULONG NTAPI PsGetCurrentProcessSessionId(VOID)
Definition: process.c:1133
PVOID NTAPI PsGetCurrentThreadWin32Thread(VOID)
Definition: thread.c:805
PVOID *typedef PHANDLE
Definition: ntsecpkg.h:455
#define STATUS_OBJECT_NAME_EXISTS
Definition: ntstatus.h:189
#define STATUS_NAME_TOO_LONG
Definition: ntstatus.h:592
NTSTRSAFEAPI RtlStringCbCopyW(_Out_writes_bytes_(cbDest) _Always_(_Post_z_) NTSTRSAFE_PWSTR pszDest, _In_ size_t cbDest, _In_ NTSTRSAFE_PCWSTR pszSrc)
Definition: ntstrsafe.h:174
NTSTRSAFEAPI RtlStringCchCatW(_Inout_updates_(cchDest) _Always_(_Post_z_) NTSTRSAFE_PWSTR pszDest, _In_ size_t cchDest, _In_ NTSTRSAFE_PCWSTR pszSrc)
Definition: ntstrsafe.h:601
NTSTRSAFEVAPI RtlStringCbPrintfExW(_Out_writes_bytes_(cbDest) _Always_(_Post_z_) NTSTRSAFE_PWSTR pszDest, _In_ size_t cbDest, _Outptr_opt_result_bytebuffer_(*pcbRemaining) NTSTRSAFE_PWSTR *ppszDestEnd, _Out_opt_ size_t *pcbRemaining, _In_ STRSAFE_DWORD dwFlags, _In_ _Printf_format_string_ NTSTRSAFE_PCWSTR pszFormat,...)
Definition: ntstrsafe.h:1335
NTSTRSAFEVAPI RtlStringCbPrintfW(_Out_writes_bytes_(cbDest) _Always_(_Post_z_) NTSTRSAFE_PWSTR pszDest, _In_ size_t cbDest, _In_ _Printf_format_string_ NTSTRSAFE_PCWSTR pszFormat,...)
Definition: ntstrsafe.h:1173
NTSTRSAFEVAPI RtlStringCchPrintfW(_Out_writes_(cchDest) _Always_(_Post_z_) NTSTRSAFE_PWSTR pszDest, _In_ size_t cchDest, _In_ _Printf_format_string_ NTSTRSAFE_PCWSTR pszFormat,...)
Definition: ntstrsafe.h:1110
NTSTRSAFEAPI RtlStringCbCopyNW(_Out_writes_bytes_(cbDest) NTSTRSAFE_PWSTR pszDest, _In_ size_t cbDest, _In_reads_bytes_(cbToCopy) STRSAFE_LPCWSTR pszSrc, _In_ size_t cbToCopy)
Definition: ntstrsafe.h:416
LRESULT FASTCALL IntDefWindowProc(PWND Wnd, UINT Msg, WPARAM wParam, LPARAM lParam, BOOL Ansi)
Definition: defwnd.c:638
LRESULT APIENTRY co_HOOK_CallHooks(INT HookId, INT Code, WPARAM wParam, LPARAM lParam)
Definition: hook.c:1102
BOOLEAN FASTCALL co_WinPosSetWindowPos(PWND Window, HWND WndInsertAfter, INT x, INT y, INT cx, INT cy, UINT flags)
Definition: winpos.c:1792
PWINSTATION_OBJECT InputWindowStation
Definition: winsta.c:21
UNICODE_STRING gustrWindowStationsDir
Definition: winsta.c:27
NTSTATUS FASTCALL IntCreateWindowStation(OUT HWINSTA *phWinSta, IN POBJECT_ATTRIBUTES ObjectAttributes, IN KPROCESSOR_MODE AccessMode, IN KPROCESSOR_MODE OwnerMode, IN ACCESS_MASK dwDesiredAccess, DWORD Unknown2, DWORD Unknown3, DWORD Unknown4, DWORD Unknown5, DWORD Unknown6)
Definition: winsta.c:458
HINSTANCE hModClient
Definition: ntuser.c:25
BOOL g_AlwaysDisplayVersion
Definition: ntuser.c:17
VOID FASTCALL UserLeave(VOID)
Definition: ntuser.c:258
PTHREADINFO gptiCurrent
Definition: ntuser.c:15
VOID FASTCALL UserEnterExclusive(VOID)
Definition: ntuser.c:249
BOOL FASTCALL UserIsEnteredExclusive(VOID)
Definition: ntuser.c:231
NTSTATUS NTAPI ObCloseHandle(IN HANDLE Handle, IN KPROCESSOR_MODE AccessMode)
Definition: obhandle.c:3379
BOOLEAN NTAPI ObFindHandleForObject(IN PEPROCESS Process, IN PVOID Object, IN POBJECT_TYPE ObjectType, IN POBJECT_HANDLE_INFORMATION HandleInformation, OUT PHANDLE Handle)
Definition: obhandle.c:2856
NTSTATUS NTAPI ObOpenObjectByPointer(IN PVOID Object, IN ULONG HandleAttributes, IN PACCESS_STATE PassedAccessState, IN ACCESS_MASK DesiredAccess, IN POBJECT_TYPE ObjectType, IN KPROCESSOR_MODE AccessMode, OUT PHANDLE Handle)
Definition: obhandle.c:2742
NTSTATUS NTAPI ObOpenObjectByName(IN POBJECT_ATTRIBUTES ObjectAttributes, IN POBJECT_TYPE ObjectType, IN KPROCESSOR_MODE AccessMode, IN PACCESS_STATE PassedAccessState, IN ACCESS_MASK DesiredAccess, IN OUT PVOID ParseContext, OUT PHANDLE Handle)
Definition: obhandle.c:2532
NTSTATUS NTAPI ObCreateObject(IN KPROCESSOR_MODE ProbeMode OPTIONAL, IN POBJECT_TYPE Type, IN POBJECT_ATTRIBUTES ObjectAttributes OPTIONAL, IN KPROCESSOR_MODE AccessMode, IN OUT PVOID ParseContext OPTIONAL, IN ULONG ObjectSize, IN ULONG PagedPoolCharge OPTIONAL, IN ULONG NonPagedPoolCharge OPTIONAL, OUT PVOID *Object)
Definition: oblife.c:1039
NTSTATUS NTAPI ObReferenceObjectByHandle(IN HANDLE Handle, IN ACCESS_MASK DesiredAccess, IN POBJECT_TYPE ObjectType, IN KPROCESSOR_MODE AccessMode, OUT PVOID *Object, OUT POBJECT_HANDLE_INFORMATION HandleInformation OPTIONAL)
Definition: obref.c:494
#define LRESULT
Definition: ole.h:14
#define LOWORD(l)
Definition: pedump.c:82
#define WS_POPUP
Definition: pedump.c:616
#define WS_VISIBLE
Definition: pedump.c:620
long LONG
Definition: pedump.c:60
unsigned short USHORT
Definition: pedump.c:61
#define WS_CLIPCHILDREN
Definition: pedump.c:619
VOID NTAPI KeDetachProcess(VOID)
Definition: procobj.c:621
VOID NTAPI KeAttachProcess(IN PKPROCESS Process)
Definition: procobj.c:582
_In_ INT cchDest
Definition: shlwapi.h:1151
#define _SEH2_GetExceptionCode()
Definition: pseh2_64.h:181
#define _SEH2_EXCEPT(...)
Definition: pseh2_64.h:82
#define _SEH2_END
Definition: pseh2_64.h:171
#define _SEH2_TRY
Definition: pseh2_64.h:71
#define _SEH2_YIELD(__stmt)
Definition: pseh2_64.h:184
#define IntSysCreateRectpRgnIndirect(prc)
Definition: region.h:93
#define list
Definition: rosglue.h:35
static __inline NTSTATUS ProbeAndCaptureUnicodeString(OUT PUNICODE_STRING Dest, IN KPROCESSOR_MODE CurrentMode, IN const UNICODE_STRING *UnsafeSrc)
Definition: probe.h:142
static __inline VOID ReleaseCapturedUnicodeString(IN PUNICODE_STRING CapturedString, IN KPROCESSOR_MODE CurrentMode)
Definition: probe.h:239
#define SharedUserData
NTSTATUS NTAPI MmMapViewOfSection(IN PVOID SectionObject, IN PEPROCESS Process, IN OUT PVOID *BaseAddress, IN ULONG_PTR ZeroBits, IN SIZE_T CommitSize, IN OUT PLARGE_INTEGER SectionOffset OPTIONAL, IN OUT PSIZE_T ViewSize, IN SECTION_INHERIT InheritDisposition, IN ULONG AllocationType, IN ULONG Protect)
Definition: section.c:4027
#define STATUS_SUCCESS
Definition: shellext.h:65
HANDLE gpidLogon
Definition: simplecall.c:15
static void Exit(void)
Definition: sock.c:1330
#define TRACE(s)
Definition: solgame.cpp:4
PULONG MinorVersion OPTIONAL
Definition: CrossNt.h:68
Definition: polytest.cpp:41
base of all file and directory entries
Definition: entries.h:83
Definition: window.c:28
ULONG_PTR ulClientDelta
Definition: ntuser.h:326
ULONG fsHooks
Definition: ntuser.h:328
PCLIENTTHREADINFO pClientThreadInfo
Definition: ntuser.h:332
DWORD dwTIFlags
Definition: ntuser.h:324
PDESKTOPINFO pDeskInfo
Definition: ntuser.h:325
Definition: ntuser.h:566
HBRUSH hbrBackground
Definition: ntuser.h:587
ULONG CURSORF_flags
Definition: cursoricon.h:16
WCHAR szDesktopName[1]
Definition: ntuser.h:158
LIST_ENTRY aphkStart[NB_HOOKS]
Definition: ntuser.h:139
struct _WND * spwnd
Definition: ntuser.h:137
PVOID pvDesktopLimit
Definition: ntuser.h:136
PVOID pvDesktopBase
Definition: ntuser.h:135
PVOID hsectionDesktop
Definition: desktop.h:22
struct _USER_MESSAGE_QUEUE * ActiveMessageQueue
Definition: desktop.h:38
LIST_ENTRY PtiList
Definition: desktop.h:25
LIST_ENTRY ListEntry
Definition: desktop.h:9
struct _WINSTATION_OBJECT * rpwinstaParent
Definition: desktop.h:11
LIST_ENTRY ShellHookWindows
Definition: desktop.h:43
PWIN32HEAP pheapDesktop
Definition: desktop.h:23
PWND spwndMessage
Definition: desktop.h:20
HWND DesktopWindow
Definition: desktop.h:40
PDESKTOPINFO pDeskInfo
Definition: desktop.h:8
DWORD dwSessionId
Definition: desktop.h:6
Definition: typedefs.h:120
struct _LIST_ENTRY * Flink
Definition: typedefs.h:121
LONG HighPart
DWORD LowPart
HDEV hDev
Definition: monitor.h:23
GENERIC_MAPPING GenericMapping
Definition: obtypes.h:358
ULONG DefaultNonPagedPoolCharge
Definition: obtypes.h:365
OBJECT_TYPE_INITIALIZER TypeInfo
Definition: obtypes.h:390
WCHAR szCSDVersion[128]
Definition: rtltypes.h:274
ULONG dwOSVersionInfoSize
Definition: rtltypes.h:269
ULONG dwBuildNumber
Definition: rtltypes.h:272
LPCWSTR lpstr
Definition: wingdi.h:3010
UINT n
Definition: wingdi.h:3009
HWINSTA hwinsta
Definition: win32.h:268
HDESK hdeskStartup
Definition: win32.h:264
W32HEAP_USER_MAPPING HeapMappings
Definition: win32.h:291
struct _DESKTOP * rpdeskStartup
Definition: win32.h:259
struct _WINSTATION_OBJECT * prpwinsta
Definition: win32.h:267
Definition: region.h:8
LIST_ENTRY ListEntry
Definition: desktop.h:67
LONG cx
Definition: kdterminal.h:27
LONG cy
Definition: kdterminal.h:28
WALLPAPER_MODE WallpaperMode
Definition: sysparams.h:144
NONCLIENTMETRICSW ncm
Definition: sysparams.h:51
ULONG cxWallpaper
Definition: sysparams.h:143
ULONG cyWallpaper
Definition: sysparams.h:143
HANDLE hbmWallpaper
Definition: sysparams.h:142
struct _DESKTOP * rpdesk
Definition: ntuser.h:194
PPROCESSINFO ppi
Definition: win32.h:88
struct _DESKTOPINFO * pDeskInfo
Definition: win32.h:93
ULONG fsHooks
Definition: win32.h:117
CLIENTTHREADINFO cti
Definition: win32.h:144
struct _CLIENTINFO * pClientInfo
Definition: win32.h:94
HDESK hdesk
Definition: win32.h:108
struct _CLIENTTHREADINFO * pcti
Definition: win32.h:91
FLONG TIF_flags
Definition: win32.h:95
struct _DESKTOP * rpdesk
Definition: win32.h:92
LIST_ENTRY WindowListHead
Definition: win32.h:155
struct _USER_MESSAGE_QUEUE * MessageQueue
Definition: win32.h:89
LIST_ENTRY PtiLink
Definition: win32.h:126
USHORT MaximumLength
Definition: env_spec_w32.h:370
struct _DESKTOP * Desktop
Definition: msgqueue.h:50
struct _W32HEAP_USER_MAPPING * Next
Definition: win32.h:199
ULONG_PTR Limit
Definition: win32.h:202
UINT flags
Definition: winuser.h:3696
struct _DESKTOP * ActiveDesktop
Definition: winsta.h:42
LIST_ENTRY DesktopListHead
Definition: winsta.h:19
Definition: ntuser.h:694
PCLS pcls
Definition: ntuser.h:720
THRDESKHEAD head
Definition: ntuser.h:695
DWORD style
Definition: ntuser.h:706
DWORD fnid
Definition: ntuser.h:709
RECT rcWindow
Definition: ntuser.h:716
LPCWSTR lpszClass
Definition: winuser.h:3067
LPCWSTR lpszName
Definition: winuser.h:3066
HINSTANCE hInstance
Definition: winuser.h:3058
LONG right
Definition: windef.h:102
LONG bottom
Definition: windef.h:103
LONG top
Definition: windef.h:101
LONG left
Definition: windef.h:100
ATOM atomSysClass[ICLS_NOTUSED+1]
Definition: ntuser.h:1060
UINT uiShellMsg
Definition: ntuser.h:1063
#define max(a, b)
Definition: svc.c:63
@ wmFill
Definition: sysparams.h:45
@ wmTile
Definition: sysparams.h:42
@ wmStretch
Definition: sysparams.h:43
@ wmFit
Definition: sysparams.h:44
#define WINVER
Definition: targetver.h:11
#define RTL_CONSTANT_STRING(s)
Definition: tunneltest.c:14
TW_UINT32 TW_UINT16 TW_UINT16 MSG
Definition: twain.h:1829
uint16_t * PWSTR
Definition: typedefs.h:56
#define MAXULONG
Definition: typedefs.h:251
unsigned char * PBOOLEAN
Definition: typedefs.h:53
#define NTAPI
Definition: typedefs.h:36
void * PVOID
Definition: typedefs.h:50
ULONG_PTR SIZE_T
Definition: typedefs.h:80
int32_t INT
Definition: typedefs.h:58
#define RtlCopyMemory(Destination, Source, Length)
Definition: typedefs.h:263
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:262
#define MAXUSHORT
Definition: typedefs.h:83
uint32_t ULONG_PTR
Definition: typedefs.h:65
#define IN
Definition: typedefs.h:39
uint16_t * PWCHAR
Definition: typedefs.h:56
#define CONTAINING_RECORD(address, type, field)
Definition: typedefs.h:260
uint32_t ULONG
Definition: typedefs.h:59
#define HIWORD(l)
Definition: typedefs.h:247
#define OUT
Definition: typedefs.h:40
#define STATUS_ACCESS_DENIED
Definition: udferr_usr.h:145
#define STATUS_UNSUCCESSFUL
Definition: udferr_usr.h:132
#define STATUS_OBJECT_NAME_COLLISION
Definition: udferr_usr.h:150
#define STATUS_OBJECT_NAME_NOT_FOUND
Definition: udferr_usr.h:149
#define ALIGN_UP(size, type)
Definition: umtypes.h:91
#define WC_DESKTOP
Definition: undocuser.h:12
HDC FASTCALL IntBeginPaint(PWND Window, PPAINTSTRUCT Ps)
Definition: painting.c:1442
BOOL FASTCALL co_UserRedrawWindow(PWND Window, const RECTL *UpdateRect, PREGION UpdateRgn, ULONG Flags)
Definition: painting.c:895
BOOL FASTCALL IntEndPaint(PWND Wnd, PPAINTSTRUCT Ps)
Definition: painting.c:1539
VOID FASTCALL IntInvalidateWindows(PWND Wnd, PREGION Rgn, ULONG Flags)
Definition: painting.c:643
_In_ HFONT _Out_ PUINT _Out_ PUINT Width
Definition: font.h:89
_In_ HFONT _Out_ PUINT Height
Definition: font.h:88
RTL_ATOM FASTCALL IntAddAtom(LPWSTR AtomName)
Definition: useratom.c:13
PWND FASTCALL UserGetWindowObject(HWND hWnd)
Definition: window.c:124
PWND FASTCALL IntGetWindowObject(HWND hWnd)
Definition: window.c:75
HDC FASTCALL UserGetWindowDC(PWND Wnd)
Definition: windc.c:947
BOOLEAN co_UserDestroyWindow(PVOID Object)
Definition: window.c:2870
PWIN32HEAP UserCreateHeap(OUT PVOID *SectionObject, IN OUT PVOID *SystemBase, IN SIZE_T HeapSize)
Definition: usrheap.c:181
static __inline PVOID UserHeapAlloc(SIZE_T Bytes)
Definition: usrheap.h:34
static __inline BOOL UserHeapFree(PVOID lpMem)
Definition: usrheap.h:44
_Must_inspect_result_ _In_ WDFCOLLECTION _In_ WDFOBJECT Object
_Must_inspect_result_ _In_ WDFDMAENABLER _In_ _In_opt_ PWDF_OBJECT_ATTRIBUTES Attributes
_Must_inspect_result_ _In_ WDFDEVICE _In_ ULONG _In_ ACCESS_MASK DesiredAccess
Definition: wdfdevice.h:2664
_Must_inspect_result_ _In_ WDFDEVICE _In_ PWDF_DEVICE_PROPERTY_DATA _In_ DEVPROPTYPE _In_ ULONG Size
Definition: wdfdevice.h:4539
_Must_inspect_result_ _In_ WDFQUEUE _In_opt_ WDFREQUEST _In_opt_ WDFFILEOBJECT _Inout_opt_ PWDF_REQUEST_PARAMETERS Parameters
Definition: wdfio.h:869
_Must_inspect_result_ _In_ WDFKEY _In_ PCUNICODE_STRING _Out_opt_ PUSHORT _Inout_opt_ PUNICODE_STRING Value
Definition: wdfregistry.h:413
POBJECT_TYPE ExDesktopObjectType
Definition: win32k.c:22
POBJECT_TYPE ExWindowStationObjectType
Definition: win32k.c:21
VOID FASTCALL SetLastNtError(_In_ NTSTATUS Status)
Definition: error.c:31
HFONT FASTCALL GreCreateFontIndirectW(_In_ const LOGFONTW *lplf)
Definition: font.c:28
BOOL NTAPI GreDeleteObject(HGDIOBJ hobj)
Definition: gdiobj.c:1165
HGDIOBJ StockObjects[]
Definition: stockobj.c:100
FORCEINLINE VOID RECTL_vOffsetRect(_Inout_ RECTL *prcl, _In_ INT cx, _In_ INT cy)
Definition: rect.h:31
VOID FASTCALL REGION_Delete(PREGION pRgn)
Definition: region.c:2449
BOOL FASTCALL GreGetTextExtentW(_In_ HDC hDC, _In_reads_(cwc) PCWCH lpwsz, _In_ INT cwc, _Out_ PSIZE psize, _In_ UINT flOpts)
Definition: text.c:77
BOOL IntCheckProcessDesktopClasses(IN PDESKTOP Desktop, IN BOOL FreeOnFailure)
Definition: class.c:1017
PCLS IntGetAndReferenceClass(PUNICODE_STRING ClassName, HINSTANCE hInstance, BOOL bDesktopThread)
Definition: class.c:1450
BOOL FASTCALL UserRegisterSystemClasses(VOID)
Definition: class.c:2337
PCURICON_OBJECT FASTCALL UserGetCurIconObject(HCURSOR hCurIcon)
Definition: cursoricon.c:200
static NTSTATUS IntMapDesktopView(IN PDESKTOP pdesk)
Definition: desktop.c:3221
HDESK APIENTRY NtUserOpenInputDesktop(DWORD dwFlags, BOOL fInherit, ACCESS_MASK dwDesiredAccess)
Definition: desktop.c:2717
BOOL APIENTRY NtUserCloseDesktop(HDESK hDesktop)
Definition: desktop.c:2757
PDESKTOP FASTCALL IntGetActiveDesktop(VOID)
Definition: desktop.c:1279
DWORD gdwDesktopSectionSize
Definition: desktop.c:46
PTHREADINFO gptiDesktopThread
Definition: desktop.c:54
BOOL APIENTRY NtUserSetThreadDesktop(HDESK hDesktop)
Definition: desktop.c:3487
HCURSOR gDesktopCursor
Definition: desktop.c:55
HDESK APIENTRY NtUserOpenDesktop(POBJECT_ATTRIBUTES ObjectAttributes, DWORD dwFlags, ACCESS_MASK dwDesiredAccess)
Definition: desktop.c:2623
NTSTATUS FASTCALL IntCreateDesktop(OUT HDESK *phDesktop, IN POBJECT_ATTRIBUTES ObjectAttributes, IN KPROCESSOR_MODE AccessMode, IN PUNICODE_STRING lpszDesktopDevice OPTIONAL, IN LPDEVMODEW lpdmw OPTIONAL, IN DWORD dwFlags, IN ACCESS_MASK dwDesiredAccess)
Definition: desktop.c:2387
HWND FASTCALL IntGetCurrentThreadDesktopWindow(VOID)
Definition: desktop.c:1438
NTSTATUS NTAPI IntDesktopOkToClose(_In_ PVOID Parameters)
Definition: desktop.c:203
NTSTATUS NTAPI InitDesktopImpl(VOID)
Definition: desktop.c:269
VOID APIENTRY UserRedrawDesktop(VOID)
Definition: desktop.c:1613
PKEVENT gpDesktopThreadStartedEvent
Definition: desktop.c:56
HDC ScreenDeviceContext
Definition: desktop.c:53
PWND FASTCALL UserGetDesktopWindow(VOID)
Definition: desktop.c:1403
BOOL IntDeRegisterShellHookWindow(HWND hWnd)
Definition: desktop.c:1800
HWND FASTCALL IntGetMessageWindow(VOID)
Definition: desktop.c:1415
NTSTATUS FASTCALL IntHideDesktop(PDESKTOP Desktop)
Definition: desktop.c:1649
VOID NTAPI DesktopThreadMain(VOID)
Definition: desktop.c:1560
HDESK UserOpenInputDesktop(DWORD dwFlags, BOOL fInherit, ACCESS_MASK dwDesiredAccess)
Definition: desktop.c:2652
HDESK FASTCALL IntGetDesktopObjectHandle(PDESKTOP DesktopObject)
Definition: desktop.c:1288
HDESK APIENTRY NtUserGetThreadDesktop(DWORD dwThreadId, HDESK hConsoleDesktop)
Definition: desktop.c:3068
VOID FASTCALL IntSetFocusMessageQueue(PUSER_MESSAGE_QUEUE NewQueue)
Definition: desktop.c:1336
NTSTATUS FASTCALL co_IntShowDesktop(PDESKTOP Desktop, ULONG Width, ULONG Height, BOOL bRedraw)
Definition: desktop.c:1631
HWND FASTCALL IntGetDesktopWindow(VOID)
Definition: desktop.c:1391
NTSTATUS NTAPI IntDesktopObjectClose(_In_ PVOID Parameters)
Definition: desktop.c:244
BOOL IntRegisterShellHookWindow(HWND hWnd)
Definition: desktop.c:1768
NTSTATUS FASTCALL IntValidateDesktopHandle(HDESK Desktop, KPROCESSOR_MODE AccessMode, ACCESS_MASK DesiredAccess, PDESKTOP *Object)
Definition: desktop.c:1254
DWORD gdwNOIOSectionSize
Definition: desktop.c:48
static VOID IntFreeDesktopHeap(IN PDESKTOP pdesk)
PUSER_MESSAGE_QUEUE FASTCALL IntGetFocusMessageQueue(VOID)
Definition: desktop.c:1324
HDESK NTAPI NtUserResolveDesktop(IN HANDLE ProcessHandle, IN PUNICODE_STRING DesktopPath, IN BOOL bInherit, OUT HWINSTA *phWinSta)
Definition: desktop.c:2864
NTSTATUS APIENTRY IntDesktopObjectParse(IN PVOID ParseObject, IN PVOID ObjectType, IN OUT PACCESS_STATE AccessState, IN KPROCESSOR_MODE AccessMode, IN ULONG Attributes, IN OUT PUNICODE_STRING CompleteName, IN OUT PUNICODE_STRING RemainingName, IN OUT PVOID Context OPTIONAL, IN PSECURITY_QUALITY_OF_SERVICE SecurityQos OPTIONAL, OUT PVOID *Object)
Definition: desktop.c:62
BOOL APIENTRY NtUserPaintDesktop(HDC hDC)
Definition: desktop.c:2814
BOOL FASTCALL DesktopWindowProc(PWND Wnd, UINT Msg, WPARAM wParam, LPARAM lParam, LRESULT *lResult)
Definition: desktop.c:1453
VOID co_IntShellHookNotify(WPARAM Message, WPARAM wParam, LPARAM lParam)
Definition: desktop.c:1706
BOOL APIENTRY NtUserSwitchDesktop(HDESK hdesk)
Definition: desktop.c:2971
NTSTATUS FASTCALL IntResolveDesktop(IN PEPROCESS Process, IN PUNICODE_STRING DesktopPath, IN BOOL bInherit, OUT HWINSTA *phWinSta, OUT HDESK *phDesktop)
Definition: desktop.c:568
BOOL FASTCALL IntPaintDesktop(HDC hDC)
Definition: desktop.c:1851
PWND FASTCALL IntGetThreadDesktopWindow(PTHREADINFO pti)
Definition: desktop.c:1376
static NTSTATUS GetSystemVersionString(OUT PWSTR pwszzVersion, IN SIZE_T cchDest, IN BOOLEAN InSafeMode, IN BOOLEAN AppendNtSystemRoot)
Definition: desktop.c:300
BOOL FASTCALL UserMessageWindowProc(PWND pwnd, UINT Msg, WPARAM wParam, LPARAM lParam, LRESULT *lResult)
Definition: desktop.c:1539
NTSTATUS NTAPI IntDesktopObjectOpen(_In_ PVOID Parameters)
Definition: desktop.c:227
DWORD gdwWinlogonSectionSize
Definition: desktop.c:49
HDC FASTCALL UserGetDesktopDC(ULONG DcType, BOOL bAltDc, BOOL ValidatehWnd)
Definition: desktop.c:1588
NTSTATUS NTAPI IntDesktopObjectDelete(_In_ PVOID Parameters)
Definition: desktop.c:172
HDESK APIENTRY NtUserCreateDesktop(POBJECT_ATTRIBUTES ObjectAttributes, PUNICODE_STRING lpszDesktopDevice, LPDEVMODEW lpdmw, DWORD dwFlags, ACCESS_MASK dwDesiredAccess)
Definition: desktop.c:2564
PDESKTOP gpdeskInputDesktop
Definition: desktop.c:52
BOOL IntSetThreadDesktop(IN HDESK hDesktop, IN BOOL FreeOnFailure)
Definition: desktop.c:3295
static HWND *FASTCALL UserBuildShellHookHwndList(PDESKTOP Desktop)
Definition: desktop.c:1665
PWND FASTCALL UserGetMessageWindow(VOID)
Definition: desktop.c:1427
static NTSTATUS IntUnmapDesktopView(IN PDESKTOP pdesk)
Definition: desktop.c:3177
static NTSTATUS UserInitializeDesktop(PDESKTOP pdesk, PUNICODE_STRING DesktopName, PWINSTATION_OBJECT pwinsta)
Definition: desktop.c:2276
PWND FASTCALL co_GetDesktopWindow(PWND pWnd)
Definition: desktop.c:1383
struct _DESKTOP * PDESKTOP
struct _DESKTOP DESKTOP
static __inline ULONG_PTR DesktopHeapGetUserDelta(VOID)
Definition: desktop.h:272
#define DT_GWL_THREADID
Definition: desktop.h:56
static __inline PVOID DesktopHeapAlloc(IN PDESKTOP Desktop, IN SIZE_T Bytes)
Definition: desktop.h:204
static __inline BOOL DesktopHeapFree(IN PDESKTOP Desktop, IN PVOID lpMem)
Definition: desktop.h:215
#define DT_GWL_PROCESSID
Definition: desktop.h:55
LRESULT FASTCALL IntDispatchMessage(PMSG pMsg)
Definition: message.c:890
BOOL FASTCALL UserPostMessage(HWND Wnd, UINT Msg, WPARAM wParam, LPARAM lParam)
Definition: message.c:1395
BOOL APIENTRY co_IntGetPeekMessage(PMSG pMsg, HWND hWnd, UINT MsgFilterMin, UINT MsgFilterMax, UINT RemoveMsg, BOOL bGMSG)
Definition: message.c:1226
LONG NTAPI UserGetSystemMetrics(ULONG Index)
Definition: metric.c:210
NTSTATUS GetProcessLuid(IN PETHREAD Thread OPTIONAL, IN PEPROCESS Process OPTIONAL, OUT PLUID Luid)
Definition: misc.c:815
PTHREADINFO FASTCALL IntTID2PTI(HANDLE id)
Definition: misc.c:42
PMONITOR NTAPI UserGetPrimaryMonitor(VOID)
Definition: monitor.c:102
BOOL FASTCALL UserDereferenceObject(PVOID Object)
Definition: object.c:644
NTSTATUS NTAPI IntAssignDesktopSecurityOnParse(_In_ PWINSTATION_OBJECT WinSta, _In_ PDESKTOP Desktop, _In_ PACCESS_STATE AccessState)
Assigns a security descriptor to the desktop object during a desktop object parse procedure.
Definition: security.c:270
NTSTATUS NTAPI IntCreateServiceSecurity(_Out_ PSECURITY_DESCRIPTOR *ServiceSd)
Creates a security descriptor for the service.
Definition: security.c:327
VOID IntFreeSecurityBuffer(_In_ PVOID Buffer)
Frees an allocated security buffer from UM memory that is been previously allocated by IntAllocateSec...
Definition: security.c:133
#define DESKTOP_WRITE
Definition: security.h:19
#define DESKTOP_EXECUTE
Definition: security.h:27
#define WINSTA_ACCESS_ALL
Definition: security.h:57
#define DESKTOP_READ
Definition: security.h:15
BOOL g_PaintDesktopVersion
Definition: sysparams.c:19
SPIVALUES gspv
Definition: sysparams.c:17
BOOL FASTCALL UserSystemParametersInfo(UINT uiAction, UINT uiParam, PVOID pvParam, UINT fWinIni)
Definition: sysparams.c:2116
#define TAG_WINSTA
Definition: tags.h:11
#define USERTAG_EVENT
Definition: tags.h:230
#define USERTAG_WINDOWLIST
Definition: tags.h:298
LONG FASTCALL co_UserSetWindowLong(HWND hWnd, DWORD Index, LONG NewValue, BOOL Ansi)
Definition: window.c:4038
PWND FASTCALL IntCreateWindow(CREATESTRUCTW *Cs, PLARGE_STRING WindowName, PCLS Class, PWND ParentWindow, PWND OwnerWindow, PVOID acbiBuffer, PDESKTOP pdeskCreated, DWORD dwVer)
Definition: window.c:1808
#define WSS_LOCKED
Definition: winsta.h:7
struct _WINSTATION_OBJECT * PWINSTATION_OBJECT
#define WSS_NOIO
Definition: winsta.h:9
SIZE_T WINAPI HeapSize(HANDLE, DWORD, LPCVOID)
#define MAKEINTATOM(i)
Definition: winbase.h:1220
ENGAPI ULONG APIENTRY EngGetLastError(VOID)
Definition: error.c:9
ENGAPI INT APIENTRY EngMulDiv(_In_ INT a, _In_ INT b, _In_ INT c)
Definition: math.c:26
ENGAPI VOID APIENTRY EngSetLastError(_In_ ULONG iError)
Definition: error.c:22
DWORD COLORREF
Definition: windef.h:94
HICON HCURSOR
Definition: windef.h:93
#define ERROR_INVALID_WINDOW_HANDLE
Definition: winerror.h:1226
#define TA_RIGHT
Definition: wingdi.h:933
#define TA_LEFT
Definition: wingdi.h:932
#define TRANSPARENT
Definition: wingdi.h:950
#define SRCCOPY
Definition: wingdi.h:333
#define PATCOPY
Definition: wingdi.h:335
#define BLACK_BRUSH
Definition: wingdi.h:896
#define TA_TOP
Definition: wingdi.h:930
#define TA_BOTTOM
Definition: wingdi.h:929
#define TA_CENTER
Definition: wingdi.h:931
#define WM_PAINT
Definition: winuser.h:1648
#define WM_ERASEBKGND
Definition: winuser.h:1653
#define WM_CLOSE
Definition: winuser.h:1649
#define SWP_NOACTIVATE
Definition: winuser.h:1253
#define SWP_NOREDRAW
Definition: winuser.h:1257
#define SM_CYVIRTUALSCREEN
Definition: winuser.h:1050
#define SM_CYSCREEN
Definition: winuser.h:971
#define WM_WINDOWPOSCHANGING
Definition: winuser.h:1689
#define WM_CREATE
Definition: winuser.h:1636
#define WH_SHELL
Definition: winuser.h:40
#define RDW_UPDATENOW
Definition: winuser.h:1231
#define RDW_ERASE
Definition: winuser.h:1222
#define WM_SYSCOLORCHANGE
Definition: winuser.h:1654
#define WM_NCCREATE
Definition: winuser.h:1711
#define SM_CXVIRTUALSCREEN
Definition: winuser.h:1049
#define RDW_ALLCHILDREN
Definition: winuser.h:1232
#define PM_REMOVE
Definition: winuser.h:1207
#define RDW_FRAME
Definition: winuser.h:1223
#define SWP_SHOWWINDOW
Definition: winuser.h:1259
#define WM_SETCURSOR
Definition: winuser.h:1664
#define SM_CLEANBOOT
Definition: winuser.h:1038
#define WM_DESTROY
Definition: winuser.h:1637
#define SM_CXSCREEN
Definition: winuser.h:970
struct _WINDOWPOS * PWINDOWPOS
#define SM_XVIRTUALSCREEN
Definition: winuser.h:1047
#define SWP_NOZORDER
Definition: winuser.h:1258
#define RDW_INVALIDATE
Definition: winuser.h:1225
#define SM_YVIRTUALSCREEN
Definition: winuser.h:1048
_In_ PVOID _Out_opt_ PULONG_PTR _Outptr_opt_ PCUNICODE_STRING * ObjectName
Definition: cmfuncs.h:64
#define IO_NO_INCREMENT
Definition: iotypes.h:598
CCHAR KPROCESSOR_MODE
Definition: ketypes.h:7
_In_ PEPROCESS _In_ KPROCESSOR_MODE AccessMode
Definition: mmfuncs.h:396
_In_ ACCESS_MASK _In_opt_ POBJECT_TYPE _In_ KPROCESSOR_MODE _Out_ PVOID _Out_opt_ POBJECT_HANDLE_INFORMATION HandleInformation
Definition: obfuncs.h:44
#define ObDereferenceObject
Definition: obfuncs.h:203
#define ObReferenceObject
Definition: obfuncs.h:204
#define DUPLICATE_SAME_ACCESS
#define PsGetCurrentProcess
Definition: psfuncs.h:17
#define RtlEqualLuid(Luid1, Luid2)
Definition: rtlfuncs.h:304
_In_opt_ PVOID _In_opt_ PUNICODE_STRING _In_ PSECURITY_DESCRIPTOR _In_ PACCESS_STATE AccessState
Definition: sefuncs.h:417
#define SYSTEM_LUID
Definition: setypes.h:700
const WCHAR * LPCWSTR
Definition: xmlstorage.h:185
__wchar_t WCHAR
Definition: xmlstorage.h:180
#define ZwCurrentProcess()